Commit f0fb2d72 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

update model for m2m eggnog - functional cat

parent e7c74843
Pipeline #19698 passed with stages
in 2 minutes and 19 seconds
...@@ -20,9 +20,15 @@ class FunctionAdmin(admin.ModelAdmin): ...@@ -20,9 +20,15 @@ class FunctionAdmin(admin.ModelAdmin):
@admin.register(EggNog) @admin.register(EggNog)
class EggNogAdmin(admin.ModelAdmin): class EggNogAdmin(admin.ModelAdmin):
list_display = ('function_id', 'name', 'functional_category') list_display = ('function_id', 'name', 'get_functional_categories')
search_fields = ('function_id', 'name') search_fields = ('function_id', 'name')
def get_functional_categories(self, obj):
if obj.functional_categories.all():
return ",".join([str(f) for f in obj.functional_categories.all()])
return '-'
get_functional_categories.short_description = 'Functional categories'
@admin.register(EggNogFunctionalCategory) @admin.register(EggNogFunctionalCategory)
class EggNogFunctionalCategoryAdmin(admin.ModelAdmin): class EggNogFunctionalCategoryAdmin(admin.ModelAdmin):
......
# Generated by Django 3.0 on 2019-12-10 14:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0014_eggnog_name_length'),
]
operations = [
migrations.AlterModelOptions(
name='eggnog',
options={'verbose_name': 'EggNOG', 'verbose_name_plural': 'EggNOGs'},
),
migrations.AlterModelOptions(
name='eggnogfunctionalcategory',
options={'verbose_name': 'EggNOG functional category', 'verbose_name_plural': 'EggNOG functional categories'},
),
migrations.AlterModelOptions(
name='keggorthology',
options={'verbose_name': 'KEGG orthology', 'verbose_name_plural': 'KEGG orthologies'},
),
migrations.RemoveField(
model_name='eggnog',
name='functional_category',
),
migrations.AddField(
model_name='eggnog',
name='functional_categories',
field=models.ManyToManyField(to='catalog.EggNogFunctionalCategory'),
),
]
...@@ -32,23 +32,8 @@ class KeggOrthology(Function): ...@@ -32,23 +32,8 @@ class KeggOrthology(Function):
super(KeggOrthology, self).__init__(source=self.SOURCE, *args, **kwargs) super(KeggOrthology, self).__init__(source=self.SOURCE, *args, **kwargs)
class Meta: class Meta:
verbose_name_plural = "Kegg orthologies" verbose_name = "KEGG orthology"
verbose_name_plural = "KEGG orthologies"
class EggNog(Function):
SOURCE = 'eggnog'
functional_category = models.ForeignKey(
'EggNogFunctionalCategory', related_name='eggnogs',
on_delete=models.SET_NULL,
null=True, blank=True
)
def __init__(self, *args, **kwargs):
super(EggNog, self).__init__(source=self.SOURCE, *args, **kwargs)
class Meta:
verbose_name_plural = "EggNog"
class EggNogFunctionalCategory(models.Model): class EggNogFunctionalCategory(models.Model):
...@@ -67,4 +52,18 @@ class EggNogFunctionalCategory(models.Model): ...@@ -67,4 +52,18 @@ class EggNogFunctionalCategory(models.Model):
return f"{self.category_id} ({self.name})" return f"{self.category_id} ({self.name})"
class Meta: class Meta:
verbose_name_plural = "EggNog Functional categories" verbose_name = "EggNOG functional category"
verbose_name_plural = "EggNOG functional categories"
class EggNog(Function):
SOURCE = 'eggnog'
functional_categories = models.ManyToManyField(EggNogFunctionalCategory)
def __init__(self, *args, **kwargs):
super(EggNog, self).__init__(source=self.SOURCE, *args, **kwargs)
class Meta:
verbose_name = "EggNOG"
verbose_name_plural = "EggNOGs"
Supports Markdown
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