1

在models.py中我需要你的帮助

from django.db import models
from datetime import datetime
from smart_selects.db_fields import ChainedForeignKey 


class Grupo(models.Model):
    class Meta:
        verbose_name_plural = 'Grupos'
    descripcion = models.CharField(max_length=30)
    informacion = models.CharField(max_length=100, null=True, blank=True)
    fecha = models.DateField(default=datetime.now())

    def __unicode__(self):
        return self.descripcion


class Origen(models.Model):
    class Meta:
        verbose_name_plural = 'Origenes'
    descripcion = models.CharField(max_length=30)

    def __unicode__(self):
        return self.descripcion


class Sexo(models.Model):
    class Meta:
        verbose_name_plural = 'Sexos'
    descripcion = models.CharField(max_length=30)

    def __unicode__(self):
        return self.descripcion


class Genetica(models.Model):
    class Meta:
        verbose_name_plural = 'Geneticas'
    descripcion = models.CharField(max_length=30)
    sexo = models.ForeignKey(Sexo)

    def __unicode__(self):
        return self.descripcion+ " | "+ unicode(self.sexo)


class Raza(models.Model):
    class Meta:
        verbose_name_plural = 'Razas'
    descripcion = models.CharField(max_length=30)

    def __unicode__(self):
        return self.descripcion


class Productor(models.Model):
    class Meta:
        verbose_name_plural = 'Productores'
    registro = models.IntegerField(max_length=10)
    descripcion = models.CharField(max_length=30)

    def __unicode__(self):
        return unicode(self.registro)+" | "+self.descripcion


class Oveja(models.Model):
    class Meta:
        verbose_name_plural = 'Ovejas'
    tatuaje = models.IntegerField(max_length=10, verbose_name="Nro. de Tatuaje")
    sexo = models.ForeignKey(Sexo)
    nacimiento = models.DateField(default=datetime.now(), verbose_name="Fecha de Nacimiento")   
    genetica = ChainedForeignKey(Genetica, chained_field="sexo", chained_model_field="sexo", show_all=False, auto_choose=True)
    productor = models.ForeignKey(Productor, verbose_name="Nro. Registro Productor", null=True, blank=True)
    origen = models.ForeignKey(Origen)
    mama = models.ForeignKey('self', null=True, blank=True)
    grupo = models.ForeignKey(Grupo)


    def __unicode__(self):
        return unicode(self.tatuaje)+ ' | '+unicode(self.productor)

我想过滤Oveja实体,当mama外键除此之外Ovejaid_sexo=1它用于添加新数据。

4

0 回答 0