Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 March 5, 2007 13:17:03

Kai K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Model help


Hi Duncan,

On 3/5/07, DuncanM <> wrote:
>
>
> The squad selector also has a foriegnkey on fixture, but also has 16
> other fields that are all foreignkeys on player.
>
>
>
> Now I have a few queries/questions.
> 1.)As you can see from the class above I have stated core=True on all
> the fields in SquadSelector except subs 1-5 because obviously a team
> must have all 11 players, but subs are a possible extra. Yet still
> when I try and leave them blank the admin page says I need to have
> them. How do I stop this from happening?

I think you have to add "blank=True" and null="True" to the fields,
that can be left out.


> 2.)My appearance class simply contains a result foreignkey and a
> player foreignkey, when I go to the admin page I select the result
> from a drop down box, then select the player from another drop down
> box. How would I go about making it so that all those players in the
> starting 11 (e.g. those not a sub) that were in the squad selector for
> that particular fixture, are automatically added to the appearance
> admin page? (e.g. so I dont have to add the fixture and player 11
> times over?)

You could overwrite the save method of you models Appearance class.
Example:

class Appearance(models.Model):
def save(self):
# add your 11 players from the squad selecter
super(Appearance, self).save()


> 3.)How would I go about creating a statistics page (now the classes
> are in place) such as player x has 10 appearances, and 3 goals (goals
> come from scorer class) I know this is a
> basic question regarding views and templates but I'm still very new to
> this, I have looked through as much of the documentation as I can but
> cannot find anywhere that details what I want?

I would recommend to read the tutorial on the django homepage:http://www.djangoproject.com/documentation/tutorial1/You could write me a pm if you still don't get it work.


> Duncan

Kai

--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#2 March 9, 2008 00:23:02

Malcolm T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Model help


On Sat, 2008-03-08 at 16:19 -0800, brydon wrote:
> I know this answer should exist somewhere in documentation or on the
> net, hopefully someone can point me there. I'm looking for model help
> and I think I can frame it best with an example. Say you're building a
> delicious like model. You have users, user have links. Those links
> have common elements such as url, title, screengrab. They also have a
> context unique to a user, like the date the user added the link.
>
> This leads to at least 3 main db tables. Users, Links, and UserLinks.
> A user adds the link tohttp://www.djangoproject.com/which results in
> a link and userlink entry. When the next user adds a link to
>http://www.djangoproject.com/, that only results in an update to
> userlink.
>
> I believe django supports this well by having a ManyToManyField in
> User for Links. It will then create the intermediary join table and
> manage it, which is perfect. The trick is that I want to add more data
> to that intermediary table, for example the date when this particular
> user added this link, etc. From a model perspective, ideally that
> extra information is simply part of the link a user has.

The ManyToManyField is for when you just care about the ends, not the
intermediate linkage. If you also want to work with the intermediate
table, use this approach:http://www.djangoproject.com/documentation/models/m2m_intermediary/There's some extra syntax coming in the future to make this type of
setup behave more like ManyToManyfield in terms of the syntax you use
when moving from one end to the other (not touching the intermediate
table), however that won't change the table setup or anything like that
from the above example.

Regards,
Malcolm

--
Remember that you are unique. Just like everyone else.http://www.pointy-stick.com/blog/--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#3 March 9, 2008 00:59:43

b.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Model help


That's helpful and I'll likely take that approach but I believe that
means I have two almost identical tables?

I'll likely get these table names wrong don't pay too much attention
to them....Say I created a UserLink class that had user, link, and
date_created. I think I'd end up with a users_user_link and a
users_userlink table which are identical except one contains the added
date_created column right?

Ideally I'd just have the one table or am I missing something?

thanks,
brydon






On Mar 8, 7:22 pm, Malcolm Tredinnick <>
wrote:
> On Sat, 2008-03-08 at 16:19 -0800, brydon wrote:
> > I know this answer should exist somewhere in documentation or on the
> > net, hopefully someone can point me there. I'm looking for model help
> > and I think I can frame it best with an example. Say you're building a
> > delicious like model. You have users, user have links. Those links
> > have common elements such as url, title, screengrab. They also have a
> > context unique to a user, like the date the user added the link.
>
> > This leads to at least 3 main db tables. Users, Links, and UserLinks.
> > A user adds the link tohttp://www.djangoproject.com/whichresults in
> > a link and userlink entry. When the next user adds a link to
> >http://www.djangoproject.com/, that only results in an update to
> > userlink.
>
> > I believe django supports this well by having a ManyToManyField in
> > User for Links. It will then create the intermediary join table and
> > manage it, which is perfect. The trick is that I want to add more data
> > to that intermediary table, for example the date when this particular
> > user added this link, etc. From a model perspective, ideally that
> > extra information is simply part of the link a user has.
>
> The ManyToManyField is for when you just care about the ends, not the
> intermediate linkage. If you also want to work with the intermediate
> table, use this approach:
>
>http://www.djangoproject.com/documentation/models/m2m_intermediary/>
> There's some extra syntax coming in the future to make this type of
> setup behave more like ManyToManyfield in terms of the syntax you use
> when moving from one end to the other (not touching the intermediate
> table), however that won't change the table setup or anything like that
> from the above example.
>
> Regards,
> Malcolm
>
> --
> Remember that you are unique. Just like everyone
> else.http://www.pointy-stick.com/blog/--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#4 March 9, 2008 01:35:45

Malcolm T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Model help


On Sat, 2008-03-08 at 16:59 -0800, brydon wrote:
> That's helpful and I'll likely take that approach but I believe that
> means I have two almost identical tables?

If you have two things related via a many-to-many relation and an
intermediate table, that's three tables serving different purposes. I
don't really understand your problem description, so I trusted you when
you said you wanted a many-to-many relation. If that's not what you
want, then don't model it that way.

Malcolm

--
Many are called, few volunteer.http://www.pointy-stick.com/blog/--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#5 March 9, 2008 02:35:54

Sam L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Model help


brydon,

You won't get two almost identical tables if you use the above linked
approach. Reason being is that the above approach effectively
constructs the additional table needed for a many-to-many relationship
explicitly. The model Writer is effectively the users_user_link table.
Not that no fields in any of the models have a ManytoMany field - the
Writer model and the two ForeignKey fields are doing the job of the
ManyToMany field.

Sam

On Mar 9, 11:59 am, brydon <> wrote:
> That's helpful and I'll likely take that approach but I believe that
> means I have two almost identical tables?
>
> I'll likely get these table names wrong don't pay too much attention
> to them....Say I created a UserLink class that had user, link, and
> date_created. I think I'd end up with a users_user_link and a
> users_userlink table which are identical except one contains the added
> date_created column right?
>
> Ideally I'd just have the one table or am I missing something?
>
> thanks,
> brydon
>
> On Mar 8, 7:22 pm, Malcolm Tredinnick <>
> wrote:
>
>
>
> > On Sat, 2008-03-08 at 16:19 -0800, brydon wrote:
> > > I know this answer should exist somewhere in documentation or on the
> > > net, hopefully someone can point me there. I'm looking for model help
> > > and I think I can frame it best with an example. Say you're building a
> > > delicious like model. You have users, user have links. Those links
> > > have common elements such as url, title, screengrab. They also have a
> > > context unique to a user, like the date the user added the link.
>
> > > This leads to at least 3 main db tables. Users, Links, and UserLinks.
> > > A user adds the link tohttp://www.djangoproject.com/whichresultsin
> > > a link and userlink entry. When the next user adds a link to
> > >http://www.djangoproject.com/, that only results in an update to
> > > userlink.
>
> > > I believe django supports this well by having a ManyToManyField in
> > > User for Links. It will then create the intermediary join table and
> > > manage it, which is perfect. The trick is that I want to add more data
> > > to that intermediary table, for example the date when this particular
> > > user added this link, etc. From a model perspective, ideally that
> > > extra information is simply part of the link a user has.
>
> > The ManyToManyField is for when you just care about the ends, not the
> > intermediate linkage. If you also want to work with the intermediate
> > table, use this approach:
>
> >http://www.djangoproject.com/documentation/models/m2m_intermediary/>
> > There's some extra syntax coming in the future to make this type of
> > setup behave more like ManyToManyfield in terms of the syntax you use
> > when moving from one end to the other (not touching the intermediate
> > table), however that won't change the table setup or anything like that
> > from the above example.
>
> > Regards,
> > Malcolm
>
> > --
> > Remember that you are unique. Just like everyone
> > else.http://www.pointy-stick.com/blog/-Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support