1 | from django.db import models
|
---|
2 | from django.contrib import admin
|
---|
3 |
|
---|
4 |
|
---|
5 | # models
|
---|
6 |
|
---|
7 | class Attribute(models.Model):
|
---|
8 | name = models.CharField(max_length=100, primary_key=True)
|
---|
9 | display_name = models.CharField(max_length=100, blank=True)
|
---|
10 |
|
---|
11 |
|
---|
12 | class AttributeValue(models.Model):
|
---|
13 | attribute = models.ForeignKey(Attribute, on_delete=models.CASCADE, related_name='values')
|
---|
14 | value = models.CharField (max_length=500, null=False)
|
---|
15 |
|
---|
16 |
|
---|
17 | # admin
|
---|
18 |
|
---|
19 | class AttributeValueInlineAdmin(admin.TabularInline):
|
---|
20 | model = AttributeValue
|
---|
21 | extra = 0
|
---|
22 |
|
---|
23 |
|
---|
24 | class AttributeAdmin(admin.ModelAdmin):
|
---|
25 | list_display = ['name', 'display_name']
|
---|
26 | inlines = (AttributeValueInlineAdmin,)
|
---|
27 |
|
---|
28 |
|
---|
29 | admin.site.register(Attribute, AttributeAdmin)
|
---|
30 | admin.site.register(AttributeValue, AttributeValueAdmin)
|
---|