Commit 772e934d authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

migration, admin

parent 26299343
from django.contrib import admin
from django.contrib.admin import site
# Register your models here.
from .models import Article, License, Namespace, Project, Repo
for model in [Article, License, Namespace, Project, Repo]:
site.register(model)
# Generated by Django 2.0.1 on 2018-01-12 10:07
from django.conf import settings
from django.db import migrations, models
import autoslug.fields
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('rainboard', '0002_forges'),
]
operations = [
migrations.CreateModel(
name='Article',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, unique=True)),
('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True)),
('year', models.PositiveSmallIntegerField()),
('url', models.URLField()),
('pdf', models.URLField()),
('authors', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='project',
name='articles',
field=models.ManyToManyField(to='rainboard.Article'),
),
]
......@@ -5,10 +5,9 @@ from django.db import models
from django.urls import reverse
import requests
from autoslug import AutoSlugField
from ndh.models import Links, NamedModel, TimeStampedModel
from ndh.utils import enum_to_choices, query_sum
from ndh.utils import enum_to_choices
from .utils import SOURCES, TARGETS
......@@ -130,7 +129,6 @@ class Forge(Links, NamedModel):
defaults={'name': data['name'], 'group': data['kind'] == 'group'})
def get_projects_gitlab(self):
self.get_namespaces_gitlab()
def update_gitlab(data):
project, created = Project.objects.get_or_create(name=data['name'])
namespace, _ = Namespace.objects.get_or_create(name=data['namespace']['name'])
......@@ -144,6 +142,8 @@ class Forge(Links, NamedModel):
project.main_namespace = namespace
project.save()
self.get_namespaces_gitlab()
for data in self.api_data('/projects'):
update_gitlab(data)
......@@ -223,7 +223,6 @@ class Repo(TimeStampedModel):
self.forked_from = data['source']['id']
class Commit(NamedModel, TimeStampedModel):
project = models.ForeignKey(Project, on_delete=models.CASCADE)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment