Ticket #29647: admin.py

File admin.py, 761 bytes (added by Alex Uralov, 6 years ago)

Models and admin classes

Line 
1from django.db import models
2from django.contrib import admin
3
4
5# models
6
7class 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
12class 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
19class AttributeValueInlineAdmin(admin.TabularInline):
20 model = AttributeValue
21 extra = 0
22
23
24class AttributeAdmin(admin.ModelAdmin):
25 list_display = ['name', 'display_name']
26 inlines = (AttributeValueInlineAdmin,)
27
28
29admin.site.register(Attribute, AttributeAdmin)
30admin.site.register(AttributeValue, AttributeValueAdmin)
Back to Top