Ticket #12749: models.py

File models.py, 841 bytes (added by Natalia Bidart, 15 years ago)
Line 
1from django.db import models
2from django.contrib import admin
3
4class Person(models.Model):
5 firstname = models.CharField(max_length=15)
6 def __str__(self):
7 return self.firstname
8
9class OutfitItem(models.Model):
10 name = models.CharField(max_length=15)
11 def __str__(self):
12 return self.name
13
14class 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
20class ShoppingWeakness(models.Model):
21 fashionista = models.ForeignKey(Fashionista)
22 item = models.ForeignKey(OutfitItem)
23
24#Admin
25
26class InlineWeakness(admin.TabularInline):
27 model = ShoppingWeakness
28 extra = 1
29
30admin.site.register(Fashionista, inlines=[InlineWeakness])
Back to Top