Re: Right way to use this ForeignKey

2006-12-03 Thread phess

Right, thanks a lot, Todd.
I guess I'm not *that* stupid after all... :) Phew! :D

I think I was actually using the wrong approach to building the
magazines. I mean, they should have been separate apps from the start.
Or else, every freaking article will be in a huge database table that
also houses articles from the other magazines. I think this is just
wrong.
The same would happen to sections: a long table of sections that aren't
really related to each other, because each of them belongs to a
different magazine.

By separating magazines into different apps, I get everything I wanted:
- separate database tables for each magazine
- the user chooses the magazine, and only the valid issues and sections
appear on the list


Anyway, as a reply to your last (extremely helpful) msg:

> If an issue belongs to only one magazine and an article belongs to only
> one issue, then including both the magazine and the issue in the article
> model is redundant, so if you can avoid it, I would.

The thing is, when I put in an article, I might not have its section
yet. Yes, I know, this is annoyingly complex and boring...

> Is this something end users will need to get at? If so, I wouldn't
> depend on the admin interface and would write my own view that would
> allow someone to pick a magazine and then have another drop-down
> (possibly updated using Ajax) that would be limited to its issues. When
> you read the form, ignore the magazine and just record the issue.

Yes, end users (the writing team) will use this Admin interface.
Emphasizing on the "with deadlines" part of Django's motto, I have to
be *really* *really* quick with this website. ;) So, no custom views
at this moment.

> If it's just you, add an ordering to issues that sorts by magazines and
> dates (or whatever) and you can type the first few characters of the
> magazine name to find yourself in the right general area.

That's what I'd been using, but it felt plain wrong.

Once again, thanks a lot!
Phess


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



Re: Right way to use this ForeignKey

2006-12-03 Thread phess

> So an article can be in more than one issue of a magazine?

Not at all. The Article belongs to only one Issue, which is what I want
the ForeignKey to mean.
I just want to limit the choices of Issues to the ones that make sense,
i.e. to the Issues that belong to the chosen Magazine.


> Just override the issue's __str__() method to include the name of the
> magazine that it should have as a foreign key in its string
> representation and you should be able to see what's what.

Yes, I'm already doing that, although I didn't show it. The issue's
__str__() returns '%s-%s' %(magazine, number)

Phess


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



Right way to use this ForeignKey

2006-12-03 Thread phess

I'm stuck at what I think should have been one of the easiest steps of
building my magazines website: the models. :(
I really feel stupid for that, so please tell me the right way to do
this.

This is what I have: Magazines, with many Issues each, and articles,
which belong to only one Magazine, and therefore should only be allowed
to belong to the chosen Magazine's Issues.

myproj/myapp/models.py:

class Magazine(models.Model):
   ...
   name = models.CharField(...)

class Issue(models.Model):
   ...
   magazine = models.ForeignKey(Magazine)
   ...

class Article(models.Model):
   ...
   magazine = models.ForeignKey(Magazine)
   # Now I want to force the displaying of only the Issues that have
   # this same Magazine as their ForeignKey relation.
   # This is how I'm trying to do this:
   issue = models.ForeignKey(Issue,
limit_choices_to{'magazine__id__eq': magazine.id})

Django tells me that ForeignKey fields have no id attribute. Ok, I knew
that already, but there's *got* to be some way of limiting the choice
of issues to the ones that belong to the same Magazine the user chose.

So, my question here would be:
How can I access the attributes of a ForeignKey "target" when building
my model?

If this is not possible in the model definition steps, then how do I do
this limiting in the Admin page?

Any hint would be great.


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



Re: Inheritance through a ForeignKey field

2006-12-01 Thread phess

I just saw the source of all my problems.

This is the code for the Article class:

class Article(models.Model):
   """This class defines an Article, with links to:
   - a Magazine,
   - a Section (which depends on the Magazine), and
   - an Issue (which also depends on the Magazine)"""

   def __str__(self):
  return self.nicetitle
   class Admin:
  pass

   title = models.CharField(maxlength=40, core=True)
   nicetitle = models.SlugField(prepopulate_from=('title'))
   magazine = models.ForeignKey(Magazine, edit_inline=False)

   # Hard part
   validsections = # How do I refer to the value (i.e., name or id) of
the magazine variable created right above?

Cheers


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



Re: Inheritance through a ForeignKey field

2006-12-01 Thread phess

Sorry, I forgot to actually *ask* the question. :)

I'm able to get a list of Sections related to 'Linux Magazine', for
example, with:

validsections = magazine.section_set.all()

This returns this list:
[, ]  # (so far I've created only
these 2 sections)

Is there a method to restrict the choices in the following line, like
this?:

section = models.ForeignKey(Section, choices=validsections)

I tried this, but got this error:
'ForeignKey' object has no attribute 'section_set'

Once again, thanks for any help.


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



Re: Inheritance through a ForeignKey field

2006-12-01 Thread phess

It did help. Thank you very much.
But the situation has changed already. :\

I'd like the Admin pages to show me only the Sections and Issues that
make sense for the Magazine I choose from the selectbox.

So, this is how my model is (sort of):

I have a Magazine class, an Issue class and a Section class.

A Magazine has many issues.
A Magazine has many sections.
Classes Section and Issue are *not* directly connected.

So,

class Section(...):
  ...
  magazine = models.ForeignKey(Magazine)


class Issue(...):
  ...
  magazine = models.ForeignKey(Magazine)

That works perfectly so far.

However, I want to add an Article, and after I choose a magazine, I
want to restrict the choices of Sections and Issues to the ones linked
to that specific magazine.

The result should be:
> User chooses 'Linux Magazine'
>> User gets to choose from all the Sections that belong to the 'Linux 
>> Magazine' instance, and *no Section* that belongs to 'Easy Linux'.
>> User gets to choose from all the Issues that belong to 'Linux Magazine', and 
>> only those.

PS: If it matters to anyone, this is for the brazilian branch of Linux
New Media AG, the publishers of Linux Magazine (international) and
Linux Magazin (Germany), and also Linux Magazine (Brazil) and Easy
Linux (Brazil).


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



Inheritance through a ForeignKey field

2006-11-30 Thread phess

I'm now building an online magazine website. Each magazine has the same
set of sections. And every article belongs to one and only one section.

So, the Article class has a ForeignKey(Section) line.

So far, so good (I guess). :)

But there are actually 2 magazines, each with its own group of
sections. When I create an article, I want the "Section" field in the
form to automatically load the "Magazine" field in the same form.

Does django handle this kind of thing?


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



html templates for generic views

2006-11-27 Thread phess

I must quickly develop a complete website, so I chose "the Web
framework for perfectionists with deadlines". ;)

In my first tests with a web-based registration mechanism, I'd like to
use default (could be quick n' dirty) templates, but these seem to be
unavailable.

Since I'm really not interested in designing webpages (being focused at
python instead), and there will be a specialist for that at a later
stage, such default templates would really speed up my project's
development.

So, is there such a default set of templates that I'm ridiculously
missing? Or am I supposed to write the ugliest possible forms for the
user to write their e-mail, username etc?

Any help would be appreciated.


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