示例#1
0
class Relating(models.Model):

    # ForeignKey to BasePerson
    baseperson = models.ForeignKey(BasePerson,
                                   models.CASCADE,
                                   related_name='relating_baseperson')
    baseperson_hidden = models.ForeignKey(BasePerson,
                                          models.CASCADE,
                                          related_name='+')

    # ForeignKey to Person
    person = models.ForeignKey(Person,
                               models.CASCADE,
                               related_name='relating_person')
    person_hidden = models.ForeignKey(Person, models.CASCADE, related_name='+')

    # ForeignKey to ProxyPerson
    proxyperson = models.ForeignKey(ProxyPerson,
                                    models.CASCADE,
                                    related_name='relating_proxyperson')
    proxyperson_hidden = models.ForeignKey(
        ProxyPerson,
        models.CASCADE,
        related_name='relating_proxyperson_hidden+')

    # ManyToManyField to BasePerson
    basepeople = models.ManyToManyField(BasePerson,
                                        related_name='relating_basepeople')
    basepeople_hidden = models.ManyToManyField(BasePerson, related_name='+')

    # ManyToManyField to Person
    people = models.ManyToManyField(Person, related_name='relating_people')
    people_hidden = models.ManyToManyField(Person, related_name='+')
示例#2
0
class BasePerson(AbstractPerson):
    # DATA fields
    data_base = models.CharField(max_length=10)
    fk_base = models.ForeignKey(Relation,
                                models.CASCADE,
                                related_name='fk_base_rel')

    # M2M fields
    m2m_base = models.ManyToManyField(Relation, related_name='m2m_base_rel')
    friends_base = models.ManyToManyField('self',
                                          related_name='friends_base',
                                          symmetrical=True)
    following_base = models.ManyToManyField('self',
                                            related_name='followers_base',
                                            symmetrical=False)

    # VIRTUAL fields
    data_not_concrete_base = models.ForeignObject(
        Relation,
        on_delete=models.CASCADE,
        from_fields=['base_non_concrete_id'],
        to_fields=['id'],
        related_name='fo_base_rel',
    )

    # GFK fields
    content_type_base = models.ForeignKey(ContentType,
                                          models.CASCADE,
                                          related_name='+')
    object_id_base = models.PositiveIntegerField()
    content_object_base = GenericForeignKey('content_type_base',
                                            'object_id_base')

    # GR fields
    generic_relation_base = GenericRelation(Relation)
示例#3
0
class SelfRefer(models.Model):
    name = models.CharField(max_length=10)
    references = models.ManyToManyField('self')
    related = models.ManyToManyField('self')

    def __str__(self):
        return self.name
示例#4
0
class Book(models.Model):
    title = models.CharField(max_length=50)
    author = models.CharField(max_length=30)
    is_published = models.BooleanField(default=False)
    authors = models.ManyToManyField(Person, related_name='books')
    fun_authors = models.ManyToManyField(FunPerson, related_name='books')
    favorite_things = GenericRelation(
        Person,
        content_type_field='favorite_thing_type',
        object_id_field='favorite_thing_id',
    )
    fun_people_favorite_things = GenericRelation(
        FunPerson,
        content_type_field='favorite_thing_type',
        object_id_field='favorite_thing_id',
    )

    published_objects = PublishedBookManager()
    annotated_objects = AnnotatedBookManager()

    class Meta:
        base_manager_name = 'annotated_objects'

    def __str__(self):
        return self.title
示例#5
0
class ArticleRef(models.Model):
    title = models.CharField(max_length=50, unique=True)
    code = models.CharField(max_length=50, unique=True)
    authors = models.ManyToManyField(ScientistRef,
                                     related_name='articles_written_set')
    reviewers = models.ManyToManyField(ScientistRef,
                                       related_name='articles_reviewed_set')
示例#6
0
 class Group(models.Model):
     primary = models.ManyToManyField(Person,
                                      through='Membership',
                                      related_name='primary')
     secondary = models.ManyToManyField(Person,
                                        through='Membership',
                                        related_name='secondary')
示例#7
0
class Entry(models.Model):
    name = models.CharField(max_length=10)
    topics = models.ManyToManyField(Tag)
    related = models.ManyToManyField(Tag, related_name="similar")

    def __str__(self):
        return self.name
示例#8
0
class Group(models.Model):
    name = models.CharField(max_length=128)
    # Membership object defined as a class
    members = models.ManyToManyField(Person, through=Membership)
    user_members = models.ManyToManyField(User, through='UserMembership')

    def __str__(self):
        return self.name
示例#9
0
class Person(models.Model):
    name = models.CharField(max_length=20)
    friends = models.ManyToManyField('self')
    idols = models.ManyToManyField('self',
                                   symmetrical=False,
                                   related_name='stalkers')

    def __str__(self):
        return self.name
示例#10
0
class Staff(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=50)
    organisation = models.CharField(max_length=100)
    tags = models.ManyToManyField(Tag, through='StaffTag')
    coworkers = models.ManyToManyField('self')

    def __str__(self):
        return self.name
示例#11
0
class Event(models.Model):
    name = models.CharField(max_length=50, unique=True)
    people = models.ManyToManyField('Person', through='IndividualCompetitor')
    special_people = models.ManyToManyField(
        'Person',
        through='ProxiedIndividualCompetitor',
        related_name='special_event_set',
    )
    teams = models.ManyToManyField('Group', through='CompetingTeam')
示例#12
0
class Car(models.Model):
    name = models.CharField(max_length=20)
    default_parts = models.ManyToManyField(Part)
    optional_parts = models.ManyToManyField(Part, related_name='cars_optional')

    class Meta:
        ordering = ('name',)

    def __str__(self):
        return self.name
示例#13
0
class Person(models.Model):
    name = models.CharField(max_length=20)
    fans = models.ManyToManyField('self', related_name='idols', symmetrical=False)
    friends = models.ManyToManyField('self')

    class Meta:
        ordering = ('name',)

    def __str__(self):
        return self.name
示例#14
0
class Article(models.Model):
    headline = models.CharField(max_length=100)
    # Assign a string as name to make sure the intermediary model is
    # correctly created. Refs #20207
    publications = models.ManyToManyField(Publication, name='publications')
    tags = models.ManyToManyField(Tag, related_name='tags')

    def __str__(self):
        return self.headline

    class Meta:
        ordering = ('headline',)
示例#15
0
文件: base.py 项目: iMerica/dj-models
class Article(models.Model):
    author = models.ForeignKey(Author, models.CASCADE)
    headline = models.CharField(max_length=50)
    pub_date = models.DateTimeField()
    categories = models.ManyToManyField(Category)
    meta_data = models.ManyToManyField(CategoryMetaData)

    class Meta:
        ordering = ('pub_date', )

    def __str__(self):
        return self.headline
示例#16
0
class Article(models.Model):
    headline = models.CharField(max_length=50)
    pub_date = models.DateTimeField()
    primary_categories = models.ManyToManyField(
        Category, related_name='primary_article_set')
    secondary_categories = models.ManyToManyField(
        Category, related_name='secondary_article_set')

    class Meta:
        ordering = ('pub_date', )

    def __str__(self):
        return self.headline
示例#17
0
class Article(models.Model):
    title = models.CharField(max_length=50, unique=True)
    code = models.CharField(max_length=50,
                            unique=True,
                            db_tablespace='idx_tbsp')
    authors = models.ManyToManyField(Scientist,
                                     related_name='articles_written_set')
    reviewers = models.ManyToManyField(Scientist,
                                       related_name='articles_reviewed_set',
                                       db_tablespace='idx_tbsp')

    class Meta:
        db_table = 'model_options_articleref'
        db_tablespace = 'tbl_tbsp'
        managed = False
示例#18
0
class Author(models.Model):
    name = models.CharField(max_length=100)
    age = models.IntegerField()
    friends = models.ManyToManyField('self', blank=True)

    def __str__(self):
        return self.name
示例#19
0
class Annotation(models.Model):
    name = models.CharField(max_length=10)
    tag = models.ForeignKey(Tag, models.CASCADE)
    notes = models.ManyToManyField(Note)

    def __str__(self):
        return self.name
示例#20
0
class ArticleIdea(models.Model):
    articles = models.ManyToManyField(
        Article,
        related_name='ideas',
        related_query_name='idea_things',
    )
    name = models.CharField(max_length=255)
示例#21
0
class Visa(models.Model):
    person = models.ForeignKey(Person, models.CASCADE)
    permissions = models.ManyToManyField(Permission, blank=True)

    def __str__(self):
        return '%s %s' % (self.person.name,
                          ', '.join(p.name for p in self.permissions.all()))
示例#22
0
class AuthorMeeting(models.Model):
    name = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)
    created = models.DateField(editable=False)

    def __str__(self):
        return self.name
示例#23
0
class FlatPage(models.Model):
    url = models.CharField(_('URL'), max_length=100, db_index=True)
    title = models.CharField(_('title'), max_length=200)
    content = models.TextField(_('content'), blank=True)
    enable_comments = models.BooleanField(_('enable comments'), default=False)
    template_name = models.CharField(
        _('template name'),
        max_length=70,
        blank=True,
        help_text=_(
            "Example: 'flatpages/contact_page.html'. If this isn't provided, "
            "the system will use 'flatpages/default.html'."),
    )
    registration_required = models.BooleanField(
        _('registration required'),
        help_text=
        _("If this is checked, only logged-in users will be able to view the page."
          ),
        default=False,
    )
    sites = models.ManyToManyField(Site, verbose_name=_('sites'))

    class Meta:
        db_table = 'django_flatpage'
        verbose_name = _('flat page')
        verbose_name_plural = _('flat pages')
        ordering = ('url', )

    def __str__(self):
        return "%s -- %s" % (self.url, self.title)

    def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
示例#24
0
class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Project',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ],
        ),
        migrations.CreateModel(
            name='Task',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ],
        ),
        migrations.AddField(
            model_name='project',
            name='tasks',
            field=models.ManyToManyField(to='Task'),
        ),
    ]
示例#25
0
class Object(models.Model):
    related_objects = models.ManyToManyField("self",
                                             db_constraint=False,
                                             symmetrical=False)

    def __str__(self):
        return str(self.id)
示例#26
0
class RefToNKChild(models.Model):
    text = models.CharField(max_length=10)
    nk_fk = models.ForeignKey(NKChild, models.CASCADE, related_name='ref_fks')
    nk_m2m = models.ManyToManyField(NKChild, related_name='ref_m2ms')

    def __str__(self):
        return '%s: Reference to %s [%s]' % (self.text, self.nk_fk, ', '.join(
            str(o) for o in self.nk_m2m.all()))
示例#27
0
class Bio(models.Model):
    author = models.OneToOneField(
        Author,
        models.CASCADE,
        primary_key=True,
        to_field='name',
    )
    books = models.ManyToManyField(Book, blank=True)
示例#28
0
class Store(models.Model):
    name = models.CharField(max_length=255)
    books = models.ManyToManyField(Book)
    original_opening = models.DateTimeField()
    friday_night_closing = models.TimeField()

    def __str__(self):
        return self.name
示例#29
0
class VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(
        models.Model):
    primary_key_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.AutoField(
        primary_key=True)
    charfield_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.CharField(
        max_length=100)
    m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.ManyToManyField(
        Person, blank=True)
示例#30
0
class Blog(models.Model):
    name = models.CharField(max_length=100)
    featured = models.ForeignKey(Article, models.CASCADE, related_name='fixtures_featured_set')
    articles = models.ManyToManyField(Article, blank=True,
                                      related_name='fixtures_articles_set')

    def __str__(self):
        return self.name