Thursday, July 19, 2012

Re: Query with 3 models

If you are comfortable with sql syntax, just pull the data you want with sql joins.

You already have the keys set up

On Thursday, July 19, 2012 5:16:42 AM UTC-4, Julio Galvez wrote:
Hi, I'm new with Django and in this Groups; I have the next models and question

class Empresa(models.Model):
usuario = models.ForeignKey(User)
empresa = models.CharField(max_length=100, unique=True)
slogan =  models.TextField()
logotipo = models.ImageField(upload_to='logos')
descripcion = models.TextField()
compra_minima = models.FloatField(verbose_name='Compra Mínima')
costo_envio = models.FloatField(verbose_name='Costo de Envío')

def __unicode__(self):
return self.empresa

class Sucursal(models.Model):
empresa = models.ForeignKey(Empresa)
direccion = models.CharField(max_length=200, null=False)
estado = models.CharField(max_length=30)
municipio = models.CharField(max_length=30)

def __unicode__(self):
return self.direccion

class Platillo(models.Model):
empresa = models.ForeignKey(Empresa)
categoria = models.ForeignKey(Categoria_platillo)
nombre_platillo = models.CharField(max_length=100, null=False, blank=False, verbose_name='Nombre del Platillo')
fotografia = models.ImageField(upload_to='platillos', verbose_name='Fotografía')
descripcion = models.TextField()
precio = models.FloatField()
dia_existencia = models.CharField(max_length=150)
fecha_publicacion = models.DateTimeField(auto_now=True)
tags = models.CharField(max_length=100)
estatus = models.BooleanField(null=False, default=True)

def __unicode__(self):
return self.nombre_platillo

class Horario(models.Model):
empresa = models.ForeignKey(Empresa)
dia = models.CharField(max_length=15)
hora_abre = models.CharField(max_length=10)
hora_cierra = models.CharField(max_length=10)

def __unicode__(self):
return self.hora_abre


Now, I want to create a result like this:

{Empresa1, Sucursal1, Platillo1, Horario1}, {Empresa1, Sucursal1, Platillo2, Horario1}, {Empresa2, Sucursal1, Platillo1, Horario1}...

I use "select_related()" method, but I can't do it

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/hSJcX7Zqf9QJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment