Sqlite create ForeignKey problem

2013-05-27 Thread Marco Bonelli
Hi, In my models I want to have an optional field to a foreign key. I tried this: classe = models.ForeignKey('Classe', null=True) But i am getting this error: Table has no column named classe_id i am using sqlite edit -- You received this message because you are subscribed to the Google

Re: ForeignKey problem

2012-07-16 Thread Kurtis Mullins
I'd suggest taking a step back from the data structure of your application, decide what you want to do with your data, and then take another stab at it. If you have more questions, I'd recommend posting your questions using your application's real domain instead of continuing to use "similar"

Re: ForeignKey problem

2012-07-06 Thread Soviet
That's exactly what I want. Should I use 'through' or just make a new Model? As I said before, with your car example.. if you just want to know how > many of a part are in a car, Then what you did is enough, then you > could have some cars, and some pieces, say > > Cars = (Motorcycle, 4x4,

Re: ForeignKey problem

2012-07-06 Thread Tomas Neme
oh, and the advantage is that you could have a car, for example car = Car.objects.get(name="4x4") car.parts.get(name="Transmission").partsincar.amount >> 2 The difference with doing it with another model is that you cannot do this, for example (or not as easily)

Re: ForeignKey problem

2012-07-06 Thread Tomas Neme
> Thanks, but damn, isn't that overly complicated (for me). Using through > looks like a easier way, but then I have to add Wheel four times and can't > just type '4' in some field, since I don't need it to exist in database four > time, just an information that there are four wheels. as I said,

Re: ForeignKey problem

2012-07-06 Thread Thomas Lockhart
On 12-07-06 10:14 AM, Soviet wrote: Thanks, but damn, isn't that overly complicated (for me). Using through looks like a easier way, but then I have to add Wheel four times and can't just type '4' in some field, since I don't need it to exist in database four time, just an information that

Re: ForeignKey problem

2012-07-06 Thread Soviet
If I'll do something like: class Car(models.Model): name = models.CharField(max_length=100) parts = models.ManyToManyField('Part', through = 'PartsInCar') class Part(models.Model): name = models.CharField(max_length=100) class PartsInCar(models.Model): car =

Re: ForeignKey problem

2012-07-06 Thread Soviet
Thanks, but damn, isn't that overly complicated (for me). Using through looks like a easier way, but then I have to add Wheel four times and can't just type '4' in some field, since I don't need it to exist in database four time, just an information that there are four wheels. W dniu piątek, 6

Re: ForeignKey problem

2012-07-06 Thread Tomas Neme
> I don't understand. It's the same wheel added four times, not four > different wheels. I guess you could implement it either way. The thing is that doing it this way would become complicated at the time you need to define what is attached where. For Lego pieces, I'd do this: class

Re: ForeignKey problem

2012-07-06 Thread Soviet
> You don't. You get all wheel objects and count them. > I don't understand. It's the same wheel added four times, not four different wheels. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit

Re: ForeignKey problem

2012-07-06 Thread Melvyn Sopacua
On 6-7-2012 15:17, Soviet wrote: > Lets try LEGO pieces. I have a LEGO set that has many pieces (ManyToMany). > But I have 4 wheels and 1 brick in that set. The 'brick' can be added with > no problem, but how do I save the information that there's 4 'wheel' > objects and not only one? You

Re: ForeignKey problem

2012-07-06 Thread Soviet
Alright, bad example. Lets try LEGO pieces. I have a LEGO set that has many pieces (ManyToMany). But I have 4 wheels and 1 brick in that set. The 'brick' can be added with no problem, but how do I save the information that there's 4 'wheel' objects and not only one? W dniu czwartek, 5 lipca

Re: ForeignKey problem

2012-07-05 Thread Tomas Neme
> But! I do have another problem. Lets ditch our football example. Let's say > that I have something like that: > > class CherryTree(models.Model): > name = models.IntegerField() > cherries = models.ManyToManyField('CherryFruit') > > class CherryFruit(models.Model): > name =

Re: ForeignKey problem

2012-07-05 Thread Soviet
Thanks a lot! After few experiments I think I get it :). But! I do have another problem. Lets ditch our football example. Let's say that I have something like that: class CherryTree(models.Model): name = models.IntegerField() cherries = models.ManyToManyField('CherryFruit') class

Re: ForeignKey problem

2012-06-25 Thread Kurtis Mullins
> > > Let me follow up on this. Say I want to add list of all Teams my Players > played for. What you're saying is that I don't have to add ForeignKey to > Team and just use team_name field from Team model? Will it work? > > This relations stuff is confusing :P. > > Haha, no problem! It'll come

Re: ForeignKey problem

2012-06-25 Thread Soviet
W dniu poniedziałek, 25 czerwca 2012 18:54:48 UTC+2 użytkownik Kurtis napisał: > > Actually, I'm pretty confused about this part :) A ForeignKey is used to > relate to another Model -- not just a Model Field -- in Django's ORM. > > So for example, if you have a Team Model and a Player Model,

Re: ForeignKey problem

2012-06-25 Thread Kurtis Mullins
> > >> The mechanism must involve deferred resolution of the second model by > passing the model class name in as a string. Without string syntax python > insists on knowing what that class is at the time it sees the reference. > Don't know more than that though ;) > >

Re: ForeignKey problem

2012-06-25 Thread Thomas Lockhart
On 12-06-25 10:02 AM, Adrian Bool wrote: On 25 Jun 2012, at 17:53, Soviet wrote: Thank you kind sir for your fast response, that worked brilliantly. Can I be cheeky and ask why does it work? :) Magic! ;-) The mechanism must involve deferred resolution of the second model by passing the

Re: ForeignKey problem

2012-06-25 Thread Adrian Bool
On 25 Jun 2012, at 17:53, Soviet wrote: > Thank you kind sir for your fast response, that worked brilliantly. > Can I be cheeky and ask why does it work? :) Magic! ;-) Although seriously, Django obviously has some code in there to handle just the situation you have come across. Sorry, I

Re: ForeignKey problem

2012-06-25 Thread Kurtis Mullins
> > [...] > > Let's say I have two models and in each I have field with ForeignKey > > relating to field in other model (hope it's clear). [...] > Actually, I'm pretty confused about this part :) A ForeignKey is used to relate to another Model -- not just a Model Field -- in Django's ORM. So for

Re: ForeignKey problem

2012-06-25 Thread Soviet
Thank you kind sir for your fast response, that worked brilliantly. Can I be cheeky and ask why does it work? :) On 25 Cze, 18:43, Adrian Bool wrote: > On 25 Jun 2012, at 17:41, Soviet wrote: > > > I'm new to this Django thing and I run into first problem :). > > > Let's say I

Re: ForeignKey problem

2012-06-25 Thread Adrian Bool
On 25 Jun 2012, at 17:41, Soviet wrote: > I'm new to this Django thing and I run into first problem :). > > Let's say I have two models and in each I have field with ForeignKey > relating to field in other model (hope it's clear). Now that I want to > run migrate with South, I'm getting

ForeignKey problem

2012-06-25 Thread Soviet
Hey I'm new to this Django thing and I run into first problem :). Let's say I have two models and in each I have field with ForeignKey relating to field in other model (hope it's clear). Now that I want to run migrate with South, I'm getting "NameError: name 'ModelName' is not defined". This is

Re: Help a newbie with his simple foreignkey problem?

2009-11-12 Thread Cody Django
Sorry - it should read: b = Book.objects.get(id=1) #new book request.user.get_profile().shelf1.add(b) #add book to shelf1 request.user.get_profile().shelf1.remove(b)#remove from shelf1 request.user.get_profile().shelf2.add(b) #add to shelf2 I

Re: Help a newbie with his simple foreignkey problem?

2009-11-12 Thread R. Gorman
> b = Book.objects.get(id=1)  #new book > request.user.get_profile().shelf1.add(b)  #add book to shelf1 > request.user.shelf1.remove(b)     #remove from shelf1 > request.user.shelf2.add(b)      #add to shelf2 Looks like you're trying to add the foreignkey to the User model instead of the

Help a newbie with his simple foreignkey problem?

2009-11-12 Thread Cody Django
Hi - I'm having a hard time wrapping my head around one-to-many relations. I'd like to be able to do this in a view: b = Book.objects.get(id=1) #new book request.user.get_profile().shelf1.add(b) #add book to shelf1 request.user.shelf1.remove(b) #remove from shelf1

Re: Foreignkey problem in admin interface

2006-06-13 Thread patrickk
maybe this helps: http://www.djangoproject.com/documentation/model_api/#blank patrick Am 13.06.2006 um 15:54 schrieb Nagy Károly: > > I have a tree model data and a foreign key is defined with a > null=True. > Generated db table is correct (field is NULL instead of NOT NULL), but > in the

Foreignkey problem in admin interface

2006-06-13 Thread Nagy Károly
I have a tree model data and a foreign key is defined with a null=True. Generated db table is correct (field is NULL instead of NOT NULL), but in the admin interface i cannot add an object with empty parent. (With not null parent it works.) And obviously i cannot add first one at all. What was i