num_in_admin equivalent in newforms

2008-11-04 Thread Xiong Chiamiov

I'm in the process of converting a bunch of sites from pre-nfa to
1.0.  One of the things I've run across is the change in inlines in
the admin interface.  Previously, there was (http://
www.djangoproject.com/documentation/0.96/model-api/#many-to-one-relationships)
a parameter called num_in_admin that, when set to =1, would show all
filled models and one blank, allowing you to have the ability to add
as many of an object as you want without having a page filled with
blank models.

The current implementation, however doesn't seem to support this
(http://docs.djangoproject.com/en/dev/ref/contrib/admin/
#inlinemodeladmin-objects).  Am I overlooking something obvious, or is
there another way to do this?
--~--~-~--~~~---~--~~
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: 'NoneType' object is not iterable

2008-11-04 Thread Xiong Chiamiov

If it works in one environment, but not another, then it might have
something to do with your settings files.  When you create your links,
are you having the href be "/enter" or "/enter/"?  I think the
middleware class you're reading about is for trailing slashes, not
preceeding ones.

On Nov 4, 9:35 am, Javi <[EMAIL PROTECTED]> wrote:
> Hello everybody!
> I'm using django 1.0-1 version and Apache as a server web. In the dev
> server everything works fine but in the production server I get the
> following error when I ask for a url:
>
> NoneType' object is not iterable
>
> Request Method:         POST
> Request URL:    http://localhostenter/
> Exception Type:         TypeError
> Exception Value:
>
> 'NoneType' object is not iterable
>
> Exception Location:     /var/lib/python-support/python2.5/django/core/
> handlers/base.py in get_response, line 77
> Python Executable:      /usr/bin/python
> Python Version:         2.5.2
>
> I think it's because the "/" after "localhost" is not added, actually
> the url in the browser ishttp://localhost/enter/
>
> I've been reading about the problem and someone speaks about creating
> a middleware class... I don't know...
>
> Is there another simpler way to sort the problem out?
>
> Thanks in advance.
>
> Greetings.
--~--~-~--~~~---~--~~
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: num_in_admin equivalent in newforms

2008-11-04 Thread Xiong Chiamiov

Actually, extra by itself does exactly what I want.  For some reason I
couldn't see it - I guess I just got caught up in the specific name.
Thanks.

On Nov 4, 10:32 am, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Nov 4, 5:57 pm, Xiong Chiamiov <[EMAIL PROTECTED]> wrote:
>
> > I'm in the process of converting a bunch of sites from pre-nfa to
> > 1.0.  One of the things I've run across is the change in inlines in
> > the admin interface.  Previously, there was 
> > (http://www.djangoproject.com/documentation/0.96/model-api/#many-to-on..)
> > a parameter called num_in_admin that, when set to =1, would show all
> > filled models and one blank, allowing you to have the ability to add
> > as many of an object as you want without having a page filled with
> > blank models.
>
> > The current implementation, however doesn't seem to support this
> > (http://docs.djangoproject.com/en/dev/ref/contrib/admin/
> > #inlinemodeladmin-objects).  Am I overlooking something obvious, or is
> > there another way to do this?
>
> Some combination of extra and max_num will do what you want.
> --
> DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



day is out of range for month

2008-09-02 Thread Xiong Chiamiov

On a site of ours, we got a 500 on Aug 31 with the error:

ImproperlyConfigured: Error while importing URLconf 'ee_website.urls':
day is out of range for month

from this line:

announcements = {'queryset':
Announcement.objects.filter(active=True,expire_date__gt=datetime.today()).order_by('-
publish_date')}

Commenting it out, and the lines that depended on it, removed the
problem.
Reverting those changes on the 2nd produced a working site.

I'm not in charge of the servers, but I believe that this one is
running an svn build that's no more than a few weeks old.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



using variable as dictionary key in templates

2008-09-18 Thread Xiong Chiamiov

Is it possible?

If in the templates I call section.foo (with section being a
dictionary), then it's the equivalent of section['foo'].  Is there a
way to call section[foo]?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



django admin - inline to FK (which has a M2M to something else) throws error

2009-07-02 Thread Xiong Chiamiov

Here are my three models:

class Faculty(models.Model):
[standard attributes]
class WorkDay(models.Model):
[standard attributes]
class OfficeHour(models.Model):
faculty = models.ForeignKey(Faculty)
day_of_week = models.ManyToManyField(WorkDay)

and in admin.py:

class OfficeHourInline(admin.TabularInline):
model = OfficeHour
class FacultyAdmin(admin.ModelAdmin):
inlines = [OfficeHourInline]

So, editing a Faculty has inlines to OfficeHours, each of which is
coupled to a WorkDay, as well.

OfficeHours, created by any means, delete just fine from their own
section in admin, or from the shell (calling delete() on them).  This
includes those created through the inline on a Faculty.  They are also
completely modifiable.  They *cannot*, however, be deleted through
Faculty's inline, raising a ValueError:

"'OfficeHour' instance needs to have a primary key value before a many-
to-many relationship can be used."

This seems silly, because I know that the OfficeHour instances *do*
have primary key values - I can see them in sqlite, not to mention
that I can delete them from their own admin section!

Anything I can find on that error seems to indicate that I have a
model that hasn't been saved yet, but I know that to not be the case.
Do I perhaps need to overload the delete() method on Faculty, or
OfficeHours?  Any advice on a direction to look is 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and chat

2009-07-02 Thread Xiong Chiamiov

On Jul 2, 3:53 am, Ivan Uemlianin  wrote:
> Dear All
>
> I am looking into using or developing a chat application for Django,
> for use in a social networking website based on the Pinax Django
> "distribution".
>
> I have searched for django-based chat applications and found very
> little.  Below I list briefly what I've found.  Please could anyone
> let me know if I've missed any significant projects.

Are you looking for a multi-user chatroom, or private chat?  I'm
guessing you want the first, but you included a jabber client in there
as well, which, to my knowledge, only supports 1-to-1 conversations.

The approach I've seen for most sites is to have a web interface to an
irc room, so that you can chat without having an irc client, or with
one, if you prefer.  I know that Rizon just announced an embeddable
client for their network, and a quick google finds all sorts of
different embeddable clients.  What specifically do you need Django-
integration for, as opposed to a standard java/javascript embeddable
thingamajig?
--~--~-~--~~~---~--~~
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: Tracking a bad import

2009-07-02 Thread Xiong Chiamiov

On Jul 1, 9:15 pm, Chhouk Voeun  wrote:
> i want to use map url (http:\\localhost:8080\main).oh i use window

Did you read the tutorial?  None of your url regexes look anything
like /main/.  And why did you hijack someone else's thread that was
about a completely different topic?
--~--~-~--~~~---~--~~
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: Keep session data between user switches

2009-07-02 Thread Xiong Chiamiov

On Jul 2, 9:18 am, mettwoch  wrote:
> Hi,
>
> I write a POS application and several users share the same terminal.
> They use a barcode scanner to point to their badge to login (works
> already). I'd like to keep the session data for every user so that
> when user A leaves the terminal and user B makes an invoice and user A
> comes back to the terminal and logs in again that he gets the terminal
> in the state he left it. I store already the last customer, product
> and documents visited in the session but they get lost after user
> switching whether I do an explicite logout() or not.
>
> Any hint?

It appears that the session data is stored in the database by default,
so you can poke around there and see which data is still around.  I
think you might be able to override logout() to not call flush(), but
you might have to override a few other methods to store sessions more
permanently than default.  If you haven't seen it, you should take a
careful read of http://docs.djangoproject.com/en/dev/topics/http/sessions/
- I'm sure you'll find more of use there than I did.
--~--~-~--~~~---~--~~
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: Incomplete file save of models.FileField.save

2009-07-02 Thread Xiong Chiamiov

On Jul 2, 5:31 am, masterclock  wrote:
> I'm using python2.6 and django 1.0.2
>
> class MyModel(Model):
>     file = models.FileField(...)
>     ...
>
> mymodel = MyModel(...)
>
> mymodel.file.save(...)
>
> but the saved file is truncated.
>
> when I use admin, the uploaded file is also incomplete.
>
> could anyone give me a reason.

Are all files truncated?  Are they truncated to a certain size?  Does
this happen whether or not you're using the development server or
something else (Apache, etc.)?  Just to make sure, have you tried
different browsers?
--~--~-~--~~~---~--~~
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: Best distro for django

2009-07-04 Thread Xiong Chiamiov

On Jul 3, 11:36 am, developingchris  wrote:
> Looking for opinion of the best distro for a developer machine for
> django.
>
> I'm on ubuntu now, its going ok. I'm having keyboard issues, and
> wondering if I should put the time in on fixing it, or just ditch it
> for say, pc-bsd, if thats what the cool django kids are using.

This is a rather silly question, as it's more of general "which distro
do you prefer" thing.

That said, I love Arch Linux absolutely, because it gives me control
over my system without having the pains that the distros "real geeks"
use (namely Slack, Gentoo) produce.  Arch's primary goal is
simplicity, and as thus, it feels very Pythonic to me.  YMMV, of
course.
--~--~-~--~~~---~--~~
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: Project creating Problem in Windows

2009-07-06 Thread Xiong Chiamiov

On Jul 6, 5:18 am, somepalli  wrote:
> I installed python 2.5.4 and DJango 1.0 in my windows xp.
>
> DJango working properly.
>
> But here i am not able get the mysite folder i am getting like
> following
>
> C:\Documents and Settings\Administrator\Desktop\django_website>django-
> admin.py startproject mysite
>
> C:\Documents and Settings\Administrator\Desktop\django_website>ls
>
> C:\Documents and Settings\Administrator\Desktop\django_website>

Which documentation are you following?  'ls' should not be a valid
windows command in the first place, unless you're using cygwin or
something.  Do you see anything in that folder if you view if using
Explorer?
--~--~-~--~~~---~--~~
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: Django as python ORM in project

2009-07-06 Thread Xiong Chiamiov

> What i want to know is that should i use django ORM for it.
> Should i use any other kind of python orm instead of django orm? But
> then i would essentially need to use 2 different systems for one
> project which does not sound like a good idea.
>
> Theoretically... can 2 somewhat different ORM's use same database
> tables successfully and without any problems?

Two ORMs could use the same tables, as long as their naming
conventions match.  There might be a way to override the names of the
tables in one of them; I don't remember any such thing for Django, but
there is much about it I don't know.

While I like Django's ORM a lot, I don't see the point in installing
Django just for its ORM.  Now, since this is server-side, you'll be
the only one having to install it, so it's not as big a deal (as
opposed to distributing a project that requires every user to install
Django), but if one of the other solutions works well, then use it.
The SO users did a good job of answering your question, so look at
what they said (and their code examples) and decide for yourself.
--~--~-~--~~~---~--~~
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: Admin of an Admin for an E-Commerce Page

2009-07-06 Thread Xiong Chiamiov

On Jul 5, 12:44 pm, Nick  wrote:
> I'm looking to write an e-commerce page with very minimal admin
> functionality, but which also has an extended admin that would
> facilitate the rest of the basic admin tasks.  For example, the basic
> admin could add products but shouldn't have to know any html or meta-
> language to do so.  They just import a few pictures, add a
> description, a few tags, and a price, amount in stock, along with
> maybe a category and type of layout, then hit the 'add' button.  The
> extended admin, would be responsible for creating the different
> layouts to be chosen from, along with adding additional categories,
> adjusting SEO meta info, portlets, etc...  The default admin module in
> Django, along with a few Django e-commerce options I have looked into,
> all seem to lump everything into the same admin area.  Is there
> anything out there that separates this functionality or should I look
> into rolling my own?  And if the answer is roll my own, do you have
> any tips as to where to start?  I'm pretty new to python & django so
> pardon me if I'm missing something obvious.

If you have things separated by models, then it's easy to change the
permissions on users to hide certain things from them.  If you're
looking for more of a basic/advanced -type interface, I think you'll
need to write custom templates for those models, with if statements to
hide and show things.
--~--~-~--~~~---~--~~
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: extracting MySQL-python-1.2.3c1.tar.gz

2009-07-06 Thread Xiong Chiamiov

On Jul 5, 6:47 am, mikel  wrote:
> Setting up Django is going fine until configuring MySQL. It requires
> MySQLdb, which I downloaded from sourceforge as MySQL-
> python-1.2.3c1.tar.gz (and MySQL-python-1.2.2.tar.gz) on Mac OS X,
> Redhat, and Windows. When I try decompressing then extracting the file
> returns error: "tar: This does not look like a tar archive". I've
> never had this problem with gzip/tar files and not sure where to look
> next. Any help on getting MySQLdb so I can move forward with Django
> would be great. Thanks!

In addition to what Nikola said, keep in mind that you don't need a
full-featured database to start developing with Django (since it will,
by default, use sqlite), and if you're setting up a production
environment, you might also take a look at postgre, which I've had
good experience with, and will be no different than mysql if you stick
to using the ORM.
--~--~-~--~~~---~--~~
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: edit form not working with imagefield

2009-07-07 Thread Xiong Chiamiov

On Jul 7, 1:22 pm, Adam Jenkins  wrote:
> I know that Dojo allows one to upload files with Ajax. It uses an iframe as
> a work around.

>From what I remember from when I was doing something like this a good
year ago, using an iframe is the accepted way of uploading files with
ajax.  You'll find tutorials, articles and blogposts all over the net
about doing so with your favorite javascript library.

In particular, take a look here:
http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



docstrings not rendering in ReST in admindocs

2009-07-07 Thread Xiong Chiamiov

I've got some fairly basic docstrings in my models, and I just
discovered the admindocs module, which does all sorts of useful
introspection stuff.  I had to install docutils before it would show,
but I did that, and now I've got documentation.

The problem is that my docstrings don't seem to be run through the
ReST parser at all, and I can't find any documentation on admindocs at
all.  The closest I can find is James Bennett's article here:
http://www.b-list.org/weblog/2007/nov/12/admin-documentation/ , and
that doesn't give me any indication that I'm doing anything wrong.
The docstrings render as expected in the online ReST renderer.

Django 1.0.2.  Any hints 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTTP Headers and User Authentication

2009-07-08 Thread Xiong Chiamiov

On Jul 8, 9:40 am, Jarmo  wrote:
> > You need to send the 'sessionid'. It's in request.COOKIES.
> So I have to send the sessionid in the HttpResponse back to the client
> for it to use, right?  I tried getting it from the Request object
> after I successfully logged in.  But it wasn't in the COOKIES
> dictionary.

There are a few different suggestions in this [1] stack overflow
question.  Since request.COOKIE['session'] didn't work, you might try
one of the others.

[1] 
http://stackoverflow.com/questions/526179/in-django-how-can-i-find-out-the-request-session-sessionid-and-use-it-as-a-varia
--~--~-~--~~~---~--~~
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: FF3 src error in django admin calendar

2009-07-08 Thread Xiong Chiamiov

On Jul 8, 1:22 am, Alastair Campbell  wrote:
> Has anyone else started getting application error emails from the
> Django admin after updating to Firefox 3.5?

Before 3.5, actually.  The function that modifies the path to the
image is called once the page has finished loading, and Firefox never
registers that the page is done (the status bar registers that it is
still waiting for something, though it is not, since this problem
persists on local pages).  I'm inclined to think that it's the result
of one of my many extensions, or some combination of them.  I haven't
taken the time, however, to go through and isolate it, nor to test
with a vanilla Firefox; I know that the problem doesn't exist in Opera
or Konqueror, though.
--~--~-~--~~~---~--~~
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: FF3 src error in django admin calendar

2009-07-08 Thread Xiong Chiamiov

Oh, I forgot to note that Firebug is very helpful in these kind of
situations, as you can call the functions explicitly and see what
happens.
--~--~-~--~~~---~--~~
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: Subclassing CharField

2009-07-30 Thread Xiong Chiamiov

On Jul 30, 7:27 am, Michael Anckaert 
wrote:
> Hello everyone,
>
> I subclassed the CharField but have run into this problem:

How did you subclass CharField?  It's difficult to say what the
problem is without seeing what you've done.
--~--~-~--~~~---~--~~
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: MEDIA_URL MEDIA_ROOT

2009-07-30 Thread Xiong Chiamiov

On Jul 30, 3:38 am, Salvatore Leone 
wrote:
> I can't download the files, probably I don't understand the MEDIA_URL
> parameter. Here it is:
> MEDIA_URL = 'http://localhost:8000/wiz/uploads/'
>
> but trying to access the files returns me a 404 error.

You shouldn't have to use MEDIA_URL at all for local development.  You
should be able to access anything located in the directory specified
by MEDIA_ROOT with /media/.
--~--~-~--~~~---~--~~
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: Oracle 11g + mod_wsgi + Apache + Django on Windows 2003 does not work

2009-07-30 Thread Xiong Chiamiov

On Jul 29, 11:57 am, tcpipmen  wrote:
> Hi All, I have no problem running Oracle 11g with django on build-in
> development server and everything is fine.  But When I setup with
> mod_wsgi with Apache I'm getting messages like below
[snip]
> The specified module could not be found.

I'm not quite sure how this works on Windows, but Apache is probably
running as a different user (rather than as you).  This means that it
has its own set of environment variables, including PATH and
PYTHONPATH, which are likely to not include the directory your module
is in.  I'm afraid I can't tell you how you would go about checking or
fixing that, however, but perhaps it'll get you off to the right start.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Prepopulating slug from foreign key

2009-05-01 Thread Xiong Chiamiov

I have these two models:

class CoursePrefix(models.Model):
prefix = models.CharField(max_length=6)
title = models.CharField(max_length=40, blank=True)
department = models.ForeignKey(Department)

def __str__(self):
return self.prefix

class Meta:
verbose_name_plural = 'Course Prefixes'
ordering = ('prefix',)

class Course(models.Model):
prefix = models.ForeignKey(CoursePrefix)
number = models.CharField('Course Number', max_length=10)
title = models.CharField(max_length=100)
slug = models.SlugField(blank=True, help_text="This should be
'PREFIX-NUMBER' eg:AG-315")
description = models.TextField(blank=True)
ge_code = models.CharField('GE Code', max_length=6, blank=True)
prerequisites = models.BooleanField('Pre-Requesites are Required',
default=False)
specific_to_instructor = models.BooleanField(default=False,
help_text="Set to True if the course applies to sustainability only if
taught by a specific instructor")

def __str__(self):
return "%s-%s: %s" % (self.prefix, self.number, self.title)

def full_number(self):
return "%s-%s" % (self.prefix,self.number)

class Meta:
ordering = ('slug', 'number', 'title')

In the admin model for Course, I'd like to prepopulate the slug with
the concatenation of prefix and number.

prepopulated_fields = {'slug': ('prefix', 'number')}

*almost* works perfectly, except that the prefix is shown by it's
foreign key id (eg "1"), rather than the name ("BAZ").  All I could
seem to find on the subject was this (http://groups.google.com/group/
django-users/browse_thread/thread/fe3cc46ce445eaea) old thread from
2007, which suggested adding a get_fields method; adding
def get_fields(self):
return self.prefix
to CoursePrefix didn't change the output.

BTW, can we use pre tags around code, or is pasting it directly into
the message the preferred way?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---