1 | from django.db import models
|
---|
2 | from django.contrib import admin
|
---|
3 |
|
---|
4 | class Person(models.Model):
|
---|
5 | firstname = models.CharField(max_length=15)
|
---|
6 | def __str__(self):
|
---|
7 | return self.firstname
|
---|
8 |
|
---|
9 | class OutfitItem(models.Model):
|
---|
10 | name = models.CharField(max_length=15)
|
---|
11 | def __str__(self):
|
---|
12 | return self.name
|
---|
13 |
|
---|
14 | class Fashionista(models.Model):
|
---|
15 | person = models.OneToOneField(Person, primary_key=True)
|
---|
16 | weaknesses = models.ManyToManyField(OutfitItem, through='ShoppingWeakness', blank=True)
|
---|
17 | def __str__(self):
|
---|
18 | return str(self.person)
|
---|
19 |
|
---|
20 | class ShoppingWeakness(models.Model):
|
---|
21 | fashionista = models.ForeignKey(Fashionista)
|
---|
22 | item = models.ForeignKey(OutfitItem)
|
---|
23 |
|
---|
24 | #Admin
|
---|
25 |
|
---|
26 | class InlineWeakness(admin.TabularInline):
|
---|
27 | model = ShoppingWeakness
|
---|
28 | extra = 1
|
---|
29 |
|
---|
30 | admin.site.register(Fashionista, inlines=[InlineWeakness])
|
---|