Re: Models, field like a list

2012-03-19 Thread Jani Tiainen
Hi,

All depends on a few factors will simple foreign key or many to many be
correct solution.

If single model B can be assigned only on a single model A then foreign key
from B to A is right choice. But if
requirement is that model B can be assigned multiple times to model A then
it's definitely many to many.

And that's pretty much how far you can get with traditional RDBMS. You can
easily write convenience
methods/properties on a model class to cut out few corners if needed.

Of course you can go in many other ways, for example storing primary key
values as a string list, and then parsing it.
It's just not good thing to do. You can easily end up with data integrity
problems like what should happen if you delete
entity from model B? or your list in model A doesn't find all entities in
model B.

On Mon, Mar 19, 2012 at 5:19 PM, Dmitry Zimnukhov wrote:

> Hi,
> If you want to retrieve list of related models with one to many
> relation, you can do it with related manager, without adding a field
> to model A.
> So, if you have model B like this:
>
> class B(models.Model):
>  a = models.ForeignKey(A)
>
> you can get related B objects like this: a_instance.b_set.all()
>
> But if you want to have an array field in your model (so that array
> data will be stored in the same table that stores model data), your db
> backend must support it and you must extend Django to support this
> functionality. That's probably not what you want.
>
> 2012/3/19 Xavier Pegenaute :
> > Hi,
> >
> > I was thinking to use a field like a list [] of another object. But I
> have
> > no a clear idea which field type should I use. Any idea?
> >
> > Ex:
> > class A:
> >bClasses = models.() # list of Foreign keys from B
> >
> >
> > I am not looking for a ManyToMany Field.
> >
> > Thanks,
> > Xavi
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Models, field like a list

2012-03-19 Thread Dmitry Zimnukhov
Hi,
If you want to retrieve list of related models with one to many
relation, you can do it with related manager, without adding a field
to model A.
So, if you have model B like this:

class B(models.Model):
 a = models.ForeignKey(A)

you can get related B objects like this: a_instance.b_set.all()

But if you want to have an array field in your model (so that array
data will be stored in the same table that stores model data), your db
backend must support it and you must extend Django to support this
functionality. That's probably not what you want.

2012/3/19 Xavier Pegenaute :
> Hi,
>
> I was thinking to use a field like a list [] of another object. But I have
> no a clear idea which field type should I use. Any idea?
>
> Ex:
> class A:
>    bClasses = models.() # list of Foreign keys from B
>
>
> I am not looking for a ManyToMany Field.
>
> Thanks,
> Xavi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Models, field like a list

2012-03-19 Thread Xavier Pegenaute

Hi,

I was thinking to use a field like a list [] of another object. But I 
have no a clear idea which field type should I use. Any idea?


Ex:
class A:
bClasses = models.() # list of Foreign keys from B


I am not looking for a ManyToMany Field.

Thanks,
Xavi

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