Re: actions & triggers

2009-11-12 Thread creeper
Yes Kenneth,
You are right. That is what I'm looking for. Thank you for the
direction.

On Nov 13, 10:37 am, Kenneth Gonsalves  wrote:
> On Friday 13 Nov 2009 10:59:45 am creeper wrote:> I'm new to Django . As well 
> versed with Drupal i would like to know
> > actions & triggers type feature in Dj. May be some of you familiar
> > with such type concept in Dj ?
>
> drupal is a cms, django is a framework. Maybe you looking for something like
> this?
>
> http://docs.djangoproject.com/en/dev/topics/signals/
> --
> regards
> Kenneth Gonsalves
> Senior Project Officer
> NRC-FOSShttp://nrcfosshelpline.in/web/

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Help a Rails refugee - how to do site specific layouts?

2009-11-12 Thread Ismail Dhorat
Hey man, your question is not entirely clear but:

If you dont want to repeat yourself, you typically would use extend
tags as everyone has said. These templates can be as deep as you want
it, (not sure about the performance impact) but you could have and i
have used this

Base Template
  |-Subtemplate
  | Micro-template

Your URL calls the last template, which 'extends' the next level up,
which in turn extends the base.

The other option is, using a template tag i.e {% get_options %} and
automatically generating the HTML required (THis could be linked to a
queryset), the documentation on templatetags will help you there.

Regards,
Ismail

On Fri, Nov 13, 2009 at 6:36 AM, Andy Mckay  wrote:
> On 09-11-12 10:35 AM, Todd Blanchard wrote:
>> I like the rails mechanism for specifying page layouts (boilerplate
>> template that surrounds the currently rendered view).
>>
>> Its simple and obvious.
>
> Use the "extends" tag. If you want rails style boilerplate, there's
> always "include"
>
> http://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
> --
>   Andy McKay
>   @clearwind
>   Training: http://clearwind.ca/training/
>   Zen: http://djangozen.com
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: actions & triggers

2009-11-12 Thread Kenneth Gonsalves
On Friday 13 Nov 2009 10:59:45 am creeper wrote:
> I'm new to Django . As well versed with Drupal i would like to know
> actions & triggers type feature in Dj. May be some of you familiar
> with such type concept in Dj ?
> 
drupal is a cms, django is a framework. Maybe you looking for something like 
this?

http://docs.djangoproject.com/en/dev/topics/signals/
-- 
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
http://nrcfosshelpline.in/web/

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




actions & triggers

2009-11-12 Thread creeper
Hi All,
I'm new to Django . As well versed with Drupal i would like to know
actions & triggers type feature in Dj. May be some of you familiar
with such type concept in Dj ?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Help a Rails refugee - how to do site specific layouts?

2009-11-12 Thread Andy Mckay
On 09-11-12 10:35 AM, Todd Blanchard wrote:
> I like the rails mechanism for specifying page layouts (boilerplate
> template that surrounds the currently rendered view).
>
> Its simple and obvious.

Use the "extends" tag. If you want rails style boilerplate, there's 
always "include"

http://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
-- 
   Andy McKay
   @clearwind
   Training: http://clearwind.ca/training/
   Zen: http://djangozen.com

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: how to save a forms.ModelForm with extra fields?

2009-11-12 Thread Andy Mckay
On 09-11-12 2:33 PM, jul wrote:
> I've got the Rating model and the AddRestaurantForm shown below. In
> order to add a rating when submitting a new restaurant, I added an
> extra field to AddRestaurantForm. Can I do that? If I can, how can I
> save separately the Restaurant instance and the rating instance (I'll
> get the user from the context)?

Sure that works just fine.

When you save the form, you'll save the restaurant instance. You can 
then get the rating from the forms.cleaned_data and save that however 
you'd like.
--
   Andy McKay
   @clearwind
   Training: http://clearwind.ca/training/
   Zen: http://djangozen.com

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Django Admin interface crashes with.

2009-11-12 Thread Matt Schinckel
On Nov 13, 1:40 pm, Rick Caudill  wrote:
> I do have non-ascii data in my database.  That is allowed, right???

Yeah, in general. What appears to be happening here (and Karen is
right, we need more to go on), but data that is being loaded into a
DecimalField contains non-ascii data.

Matt.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Django Admin interface crashes with.

2009-11-12 Thread Karen Tracey
On Thu, Nov 12, 2009 at 10:40 PM, Rick Caudill  wrote:

> I do have non-ascii data in my database.  That is allowed, right???
>
>
Certainly.  Perhaps if you gave a few more clues someone could help.

What are you doing in the admin interface when the exception is raised?

If the activity is obviously tied to a particular model (adding, changing),
how is that model defined?  If you have specified any customized forms for
the admin for this model, they would be helpful to see also.

What is the full traceback that goes with the error?

Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Django Admin interface crashes with.

2009-11-12 Thread Rick Caudill
I do have non-ascii data in my database.  That is allowed, right???



On Thu, Nov 12, 2009 at 6:55 PM, Matt Schinckel wrote:

> On Nov 13, 7:06 am, Rick Caudill  wrote:
> > Hi Everyone,
> >
> > This is my first time posting but I have been using Django for about a
> > year now and love it.  I am having one problem that I can't solve
> > though and it is taking too long so I thought I would ask and see if
> > someone can help me.  So I have a Admin interface that is crashing.
> > The error that I am getting is:
> >
> > DjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in
> > position 5: ordinal not in range(128). You passed in
> >  ( > 'django.forms.forms.BoundField'>)
> >
> > Can anyone help with this
>
> It looks like you have a non-ascii character in your source file, or
> some data that is in your database.
>
> Matt.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




George Lund is out of the office.

2009-11-12 Thread glund
I will be out of the office starting  12/11/2009 and will not return until
17/11/2009.

For urgent enquiries, please telephone extension 606.  For internal GMN or
GNPD support, please fill out a request via http://trips.mintel.co.uk/ .


http://www.mintel.com
providing insight + impact

Follow Mintel on Twitter: http://twitter.com/mintelnews

Please consider the environment before printing this email.

Mintel International
London Office:
--
Mintel International Group Ltd (Mintel)
18-19 Long Lane
London EC1A 9PL
UK
Registered in England: Number 1475918.
VAT Number: GB 232 9342 72
Tel: +44 (0) 20 7606 4533
Fax: +44 (o) 20 7606 5932
E-mail: i...@mintel.com

London - Chicago - Sydney - Shanghai - Tokyo - Belfast -- More contact details 
at http://www.mintel.com/contactus.htm.

Notice
--
This email may contain information that is privileged, confidential or 
otherwise protected from disclosure. It must not be used by, or its contents 
copied or disclosed to, persons other than the addressee. If you have received 
this email in error please notify the sender immediately and delete the email. 
Any views or opinions expressed in this message are solely those of the author, 
and do not necessarily reflect those of Mintel.

No Mintel staff are authorised to make purchases using email or over the 
internet, and any contracts so performed are invalid.

Warning
--
It is the responsibility of the recipient to ensure that the onward 
transmission, opening or use of this message and any attachments will not 
adversely affect their systems or data. Please carry out such virus and other 
checks, as you consider appropriate.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Making the case for Django (vs. Drupal)

2009-11-12 Thread Kenneth Gonsalves
On Friday 13 Nov 2009 4:26:44 am scot.hac...@gmail.com wrote:
> Thanks everyone for the additional comments. Draft #2 is up now, with
> substantial changes and additions based on your feedback.
> 
> Yes, I'd like to get feedback from some  Drupal people, but again want
> to focus on devs who have worked in both systems. If you know of
> anyone who has, feel free to point them to the document.
> 
> http://birdhouse.org/blog/2009/11/11/drupal-or-django/
> 

looks like you have missed out on security - count the number of critical 
holes in drupal over the past year with the one hole in django in the past 4 
years. btw, I tried to comment on your blog, but was rejected saying I was 
behind a proxy. Given that practically any one on a LAN is behind a proxy, 
this in practice prevents comments.
-- 
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
http://nrcfosshelpline.in/web/

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Django Admin interface crashes with.

2009-11-12 Thread Matt Schinckel
On Nov 13, 7:06 am, Rick Caudill  wrote:
> Hi Everyone,
>
> This is my first time posting but I have been using Django for about a
> year now and love it.  I am having one problem that I can't solve
> though and it is taking too long so I thought I would ask and see if
> someone can help me.  So I have a Admin interface that is crashing.
> The error that I am getting is:
>
> DjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in
> position 5: ordinal not in range(128). You passed in
>  ( 'django.forms.forms.BoundField'>)
>
> Can anyone help with this

It looks like you have a non-ascii character in your source file, or
some data that is in your database.

Matt.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




question about facebook connect and django voting

2009-11-12 Thread uno...@gmail.com
I'm trying to find the most efficient way to accomplish the below:

I have a list of users (facebook friends) for a user - these users are
objects of the Django User model:
[friend1,friend2, friend3..]

I use the django voting app where users can vote on an item.

the resulting page has 10 items and for each item, it will list all
the friends who have voted on that item:

item1:
 friend1, friend3 also voted on item1

item2:
friend2 voted on item2

.

item10:
friend1 voted on item10

What is the best (or rather most efficient) way to get the list of
friends who voted on each item ?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Apache2 installation

2009-11-12 Thread Zeynel
Hello,

I've been trying to port my app to apache2 server from the django
development server. After trying all day, I now see the admin page but
I don't see my app. Hosting co is not helping because they say this is
"pure django."

Is there someone familiar with this process and could you point me to
the right document or help if you can.

I just copied the app directory to the apache server

~/webapps/django/sw1/wkw1

admin.py and urls.py are same.

I connect to the server with Putty and cd to

~/webapps/django/sw1

and run

python2.5 manage.py syncdb

then I cd to

~/webapps/django/apache2/bin

and

./restart

But this has no effect. I still see the standard admin without my app.

http://www.swimswith.com/admin/

Thanks!

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Making the case for Django (vs. Drupal)

2009-11-12 Thread scot.hac...@gmail.com
Thanks everyone for the additional comments. Draft #2 is up now, with
substantial changes and additions based on your feedback.

Yes, I'd like to get feedback from some  Drupal people, but again want
to focus on devs who have worked in *both* systems. If you know of
anyone who has, feel free to point them to the document.

http://birdhouse.org/blog/2009/11/11/drupal-or-django/

./s

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Django Admin interface crashes with.

2009-11-12 Thread Rick Caudill
Hi Everyone,

This is my first time posting but I have been using Django for about a
year now and love it.  I am having one problem that I can't solve
though and it is taking too long so I thought I would ask and see if
someone can help me.  So I have a Admin interface that is crashing.
The error that I am getting is:


DjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in
position 5: ordinal not in range(128). You passed in
 ()




Can anyone help with 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-us...@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=.




how to save a forms.ModelForm with extra fields?

2009-11-12 Thread jul
Hi

I've got the Rating model and the AddRestaurantForm shown below. In
order to add a rating when submitting a new restaurant, I added an
extra field to AddRestaurantForm. Can I do that? If I can, how can I
save separately the Restaurant instance and the rating instance (I'll
get the user from the context)?

thanks
jul

class Rating(models.Model):

user = models.ForeignKey(User)
restaurant = models.ForeignKey(Restaurant)
rating = models.PositiveSmallIntegerField()


class AddRestaurantForm(ModelForm):

rating = models.IntegerField()

class Meta:
model = Restaurant




--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Help a Rails refugee - how to do site specific layouts?

2009-11-12 Thread Bill Freeman
I haven't done rails, but my boilerplate is in a template that is
"extended" by the
page specific templates.  In fact, I have multiple levels: section
specific boilerplate
templates that extend a site wide template, with the section  specific templates
being extended by the page (type) specific templates.

Look at the "extends" and "block" tags in the template tags reference
and tutorial.

It's seems easy to misunderstand the documentation on these, so let me try a
phrase or two:  A template which will be extended provides one or more holes
which the extending templates can fill, by using the block tag.  The
extending template
fills it with the block tag.  block tags are named so that they can be
matched up.  If an
extending template does not fill a particular block in the extended
template, then that
block's content in the extended template is used.  If the extending
template uses that
block, then it's content is used instead.  Stuff in an extending
template that is not in a
block, or which is in a block that the extended template doesn't have
a block by that name,
is not sent to the browser (is not rendered).  See also the variable
block.super, which allows
you to add to rather than replace content from the extended template.

Also see the "include" tag, but if you use it very much, you probably
don't understand extends.

Bill

On Thu, Nov 12, 2009 at 1:35 PM, Todd Blanchard  wrote:
> I like the rails mechanism for specifying page layouts (boilerplate
> template that surrounds the currently rendered view).
>
> Its simple and obvious.
>
> I cannot, having read most of two books on django now along with the
> website stuff, figure out how to do the same thing in django.
>
> Also, I'm building a multiple-domain site and using the sites module
> so I want different layouts for different sites.
>
> Can someone point me an example or a module or something?
>
> Thx
>
> -Todd
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




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 think something like this works:

Class Book
#details
Class Shelf1
user = foreignkey(UserProfile)
book = foreignkey(related_name ="shelf1")
Class Shelf2
user = foreignkey(UserProfile)
book = foreignkey(related_name="shelf2")
Class UserProfile
user = foreignkey(User, unique = True)

but it doesn't look very nice...  I'd prefer to find a way to do
something like this:

b = Book.objects.get(id=1)   #new book
request.user.get_profile().shelf.1.add(b)  #add book to shelf1
request.user.get_profile().shelf.1.remove(b)#remove from shelf1
request.user.get_profile().shelf.2.add(b)  #add to shelf2

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Changing order in which inlines are displayed in Admin

2009-11-12 Thread joshuakarjala
checkout - http://www.djangosnippets.org/snippets/1489/

I have used this in one project successfully - if you want drag'n'drop

Otherwise just add:

class Meta:
ordering = ('order',)


to you model - and the admin should adhere to the "order"


On Nov 12, 3:16 pm, Joseph Wakeling  wrote:
> Hello all,
>
> A little query I haven't been able to find an answer to in docs or
> through Google.
>
> I've got a little app on my site to create menus -- it's adapted
> (updated to latest Django) from the menu app described at rossp.org.
>
> Anyway, here are the classes defined in admin.py:
>
> ###
> class MenuItemInline(admin.TabularInline):
>         model = MenuItem
>         extra = 3
>
> class MenuAdmin(admin.ModelAdmin):
>         inlines = [MenuItemInline]
>
> admin.site.register(Menu,MenuAdmin)
> ###
>
> So, each Menu has several inline elements, MenuItems.
>
> Each MenuItem has a class variable 'order' which determines what order
> the items will be listed in (lowest=first).  But in the admin view,
> MenuItems belonging to a menu are listed in the order they were
> created.  I'd like them to be sorted by MenuItem.order, but can't work
> out how: I've tried setting 'ordering' elements in either MenuItem or
> MenuItemInline, but it doesn't work.
>
> Can anyone advise?
>
> Thanks & best wishes,
>
>       -- Joe

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Changing order in which inlines are displayed in Admin

2009-11-12 Thread Joseph Wakeling
Hello all,

A little query I haven't been able to find an answer to in docs or
through Google.

I've got a little app on my site to create menus -- it's adapted
(updated to latest Django) from the menu app described at rossp.org.

Anyway, here are the classes defined in admin.py:

###
class MenuItemInline(admin.TabularInline):
model = MenuItem
extra = 3

class MenuAdmin(admin.ModelAdmin):
inlines = [MenuItemInline]

admin.site.register(Menu,MenuAdmin)
###

So, each Menu has several inline elements, MenuItems.

Each MenuItem has a class variable 'order' which determines what order
the items will be listed in (lowest=first).  But in the admin view,
MenuItems belonging to a menu are listed in the order they were
created.  I'd like them to be sorted by MenuItem.order, but can't work
out how: I've tried setting 'ordering' elements in either MenuItem or
MenuItemInline, but it doesn't work.

Can anyone advise?

Thanks & best wishes,

  -- Joe

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: QuerySet Question

2009-11-12 Thread Tomasz Zieliński
On 12 Lis, 16:12, Chris  wrote:
> Is there a way of getting a model function to access user details so
> that I can do a simple "if track.owned" in the template? Is there a
> better solution to doing it in the view? Is there something I have not
> thought of? What would be the "best practice" solution to this?
>

Just some quick ideas (after 10h of work, so watch out ;)):

1. You can write custom tag {%ifowned track request.user%}

2. You can try something less elegant:

{%for user in track.m2m_users.all%}
{%ifequal user request.user%}

{%endifequal%}
{%endfor%}

- but it's only good for small apps, as a temp solution.

--
Tomasz Zieliński
http://pyconsultant.eu

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Increment a value in a database table field

2009-11-12 Thread scot.hac...@gmail.com

On Nov 12, 7:51 am, Denis Bahati  wrote:
> Hi All,
>
> I have a field with an integer value which needs to be incremented
> every time any user updates its status within a week. If that week has
> passed it should insert a new row. Now i was trying to figure out but
> didn't get any concept on how to go through. Please any idea?

You don't mention how you're tracking dates or weeks (is that a
related model, or... ?) but this would be the general idea:

- get the timestamp of the last update to that field and compare it to
the current timestamp

if ... : #  interval is less than a week:
foo = MyModel.objects.get(...)
foo.counter = foo.counter + 1
else : interval is more than a week
foo = MyModel()
foo.counter = 1

foo.save()

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Dynamic tables?

2009-11-12 Thread joshuakarjala
Hi,

I'm trying to build a small app to create size charts like:
http://www.steepplanet.com/prodimages/Giordana/size_chart.jpg

So each size chart need to have it's own number of necessary columns
and rows. And each size chart can be assigned to any amount of
brands.

So my models.py looks like

from django.db import models
import django_tables as tables
from sizechart.translation import TranslationModel

class Brand(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(help_text='Automatically built from name.')

class Meta:
ordering = ["name"]
verbose_name_plural = "Brands"

def __unicode__(self):
return self.name

class SizeChart(TranslationModel):
brands = models.ManyToManyField("sizechart.Brand", blank=True, )
name = models.CharField(max_length=255)

class Meta:
ordering = ["name"]
verbose_name_plural = "Size charts"

class Translation:
fields = ['name', ]

def __unicode__(self):
return self.name

class Row(models.Model):
sizechart = models.ForeignKey("sizechart.SizeChart")

def __unicode__(self):
return u"Row"

class Column(TranslationModel):
"""(Column description)"""
row = models.ForeignKey("sizechart.Row")
value = models.CharField(blank=True, max_length=100)

class Translation:
field = ['value', ]

def __unicode__(self):
return u"Column"


and admin.py

from django.contrib import admin
from sizechart.models import Brand, SizeChart, Row, Column

class SizeChartInline(admin.TabularInline):
model = SizeChart.brands.through
extra = 1
max_num = 10

class ColumnInline(admin.StackedInline):
model = Column
extra = 1
max_num = 10
classes = ('collapse-open',)
allow_add = True

class RowInline(admin.StackedInline):
model = Row
extra = 1
max_num = 10
classes = ('collapse-open',)
allow_add = True
inlines = (ColumnInline)

class BrandAdmin(admin.ModelAdmin):
list_display = ('name', 'slug', )
search_fields = ('name', 'slug', )
prepopulated_fields = {"slug" : ('name',)}
inlines = (SizeChartInline, )

class SizeChartAdmin(admin.ModelAdmin):
list_display = ('name', )
search_fields = ('name', )
inlines = (RowInline, )

admin.site.register(Brand, BrandAdmin)
admin.site.register(SizeChart, SizeChartAdmin)






But the ColumnInline doesn't seem to register.

Does anyone have a better idea of how to implement 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-us...@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=.




Re: CSV to JSON snippet

2009-11-12 Thread Zeynel
Hi,

my project is in C:/sw1/wkw1
models are in C:/sw1/wkw1/models.py

Model name is Lawyer.

So, in the python shell I import simplejson with

from django.utils import simplejson

then I enter

csv2json.py sw.csv wkw1.Lawyer


and I get the error

>>> from django.utils import simplejson
>>> csv2json.py sw.csv wkw1.Lawyer
  File "", line 1
csv2json.py sw.csv wkw1.Lawyer
 ^
SyntaxError: invalid syntax
>>>

What am I doing wrong?

On Nov 12, 1:57 pm, "R. Gorman"  wrote:
> What is the error message you are receiving?
>
> R.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




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 UserProfile model. If you go:

request.user.userprofile_set.add(b)

You should have the object added. You can confirm that the userprofile
model is associated with the User model in the python shell using the
command dir(User) after you've imported the User model. You should see
'userprofile_set'. Or you could user:

p = request.user.get_profile()
p.shelf1.add(b)

R.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: CSV to JSON snippet

2009-11-12 Thread R. Gorman
What is the error message you are receiving?

R.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: ModelForm usage

2009-11-12 Thread pjrhar...@gmail.com
> - first try for empty record, expecting an empty Project-object to be created
> from the form automatically:
> projectForm = forms.ProjectForm()
> projectForm.save()
> => result: 'ProjectForm' object has no attribute 'cleaned_data'
You need to run the clean method on the form to make sure the data is
valid, for example:

projectForm = forms.ProjectForm()
if projectForm.is_valid(): #this runs clean()
projectForm.save()
else:
print projectForm.errors

I would expect this to just print lots of errors at you because your
model doesn't allow those fields to be blank. I'm slightly suspect
that some of your example here isn't accurate though, as you say you
can save a blank model which given your model definition would raise
an error.

Peter

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




CSV to JSON snippet

2009-11-12 Thread Zeynel
Hello,

I am trying to use this CSV to JSon Fixture snippet but I couldn't
make it work.

http://www.djangosnippets.org/snippets/1680/

Can anyone help me to run this snippet.

I copy the instruction below.

Thank you.

--
The instructions for csv2json.py

To run script

csv2json.py input_file_name model_name

e.g. csv2json.py airport.csv app.airport.Airport

Note: input_file_name should be a path relative to where this script
is.

Scripts depends on simplejson module.

The module can just be placed in a sub-folder to the script to make it
easier to import.

If you use the same Python binary that you use for your Django site,
you could use the Django import instead:

from django.utils import simplejson

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Help a Rails refugee - how to do site specific layouts?

2009-11-12 Thread Todd Blanchard
I like the rails mechanism for specifying page layouts (boilerplate  
template that surrounds the currently rendered view).

Its simple and obvious.

I cannot, having read most of two books on django now along with the  
website stuff, figure out how to do the same thing in django.

Also, I'm building a multiple-domain site and using the sites module  
so I want different layouts for different sites.

Can someone point me an example or a module or something?

Thx

-Todd

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




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
request.user.shelf2.add(b)  #add to shelf2

Both shelves are exactly the same, and each user always only has two
shelves.  The shelf objects are create and assigned to the UserProfile
variables upon creation of the UserProfile.  I figure the models
should be organized like so:

Class Book(models.Model)
#book fields

Class Shelf(models.Model)
books = models.foreignkey(book)
def add(self, b):
self.books.append(b) #not sure about this
def remove(self, Book):
self.books.remove(b) #not sure about this

Class UserProfile(models.Model):
   shelf1 = models.foreignkey(Shelf)
   shelf2 = models.foreignkey(Shelf)

I don't understand how to add and remove objects from a one-to-many
relation.  According to the docs, going backward through a foreignkey
relation makes available queryset methods such as .add, .clear,
and .remove - but there aren't similar methods for going forward?

Thank you for your insight!

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




how to pass a session variable into a test request?

2009-11-12 Thread Phlip
Djangoes:

This is not working (1.0.1 and 1.1.1):

uri = urlresolvers.reverse('basket')
self.client.session['cart'] = self.cart.pk
response = self.client.post(uri)

The Google traffic on this topic is a confusing mishmash of
workarounds. (Take out the session object and call .save() on it, I
can't because it's not a dict, I'm not logged in yet, etc.) I tried
all that stuff and couldn't affect the bug.

Any tips?

--
  Phlip

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: wsgi config

2009-11-12 Thread Angel Cruz
BTW,
Aliases are usually one word and so I would have aliased your site media as:

Alias /site_media/ "C:/Program Files/Apache Software
Foundation/Apache2.2/htdocs/
site_media/"


On Thu, Nov 12, 2009 at 8:49 AM, Angel Cruz  wrote:

> Does it look like this now?  This should work:
>
> Alias /media/ "C:/Program Files/Apache Software
> Foundation/Apache2.2/htdocs/media/"
>
>  Foundation/Apache2.2/htdocs/media/">
>
> Order allow,deny
> Allow from all
> 
>
>
> Alias /peergw/site_media/ "C:/Program Files/Apache Software
> Foundation/Apache2.2/htdocs/site_media/"
>
>  Foundation/Apache2.2/htdocs/site_media/">
>
> Order allow,deny
> Allow from all
> 
>
>
> 
> Order deny,allow
> Allow from all
> 
>
>
> On Wed, Nov 11, 2009 at 12:32 AM, knight  wrote:
>
>>
>> Hi,
>>
>> Thanks for the reply.It helps for the admin media.
>> But my site_media (static files) still don't work.
>> Do you have another idea what my problem is?
>>
>> Thanks, Arshavski Alexander.
>>
>> On Nov 11, 12:31 am, Angel Cruz  wrote:
>> > Maybe the backslash is a problem.
>> >
>> > Here is how my media alias looks like:
>> >
>> > Alias /media/ "C:/Program Files/Apache Software
>> > Foundation/Apache2.2/htdocs/django/media/"
>> > > > Foundation/Apache2.2/htdocs/django/media/">
>> > Order allow,deny
>> > Allow from all
>> > 
>> >
>> >
>> >
>> > On Sun, Nov 8, 2009 at 11:37 PM, knight  wrote:
>> >
>> > > Hi. I have a problem with configuring my django site with mod_wsgi.
>> > > My httpd.conf is:
>> >
>> > > LoadModule wsgi_module modules/mod-wsgi.so
>> > > WSGIScriptAlias /peergw C:/mxhw/mx30/django.wsgi
>> >
>> > > 
>> > >Order deny,allow
>> > >allow from all
>> > > 
>> >
>> > > Alias /media/ "C:\Program Files\Apache Software Foundation
>> > > \Apache2.2\htdocs\media"
>> > > Alias /peergw/site_media/ "C:\Program Files\Apache Software Foundation
>> > > \Apache2.2\htdocs\site_media"
>> >
>> > > > > > \Apache2.2\htdocs">
>> > > Order deny,allow
>> > > Allow from all
>> > > 
>> >
>> > > I want my site to run on /peergw since I have many instances on the
>> > > server and each one running with the different prefix.
>> > > Everything works fine except all the images - I can't see static media
>> > > files both in admin and my site.
>> > > When I go to "/site_media//image" and not
>> "/peergw/site_media//
>> > > image", I do see the image.
>> > > What am I doing wrong?
>> > > By the way, I'm running on Vista, but I have the same problem on XP.
>> >
>> > > Thanks, Arshavski Alexander.
>> --~--~-~--~~~---~--~~
>> 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-us...@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=.




Re: Model Theory 101 - Video Sharing App

2009-11-12 Thread Fred Chevitarese
Hello ...
I've made one app as you like...

http://code.google.com/p/django-youtube-syncronizer/

;)

http://chevitarese.wordpress.com
Fred Chevitarese - GNU/Linux


2009/8/28 thornomad 

>
> Hi thanks for the response - I had looked at oembed, but it didn't
> seem like it would grab the title, description, play count, etc ...
> which was the information I was going for.  There is also a markdown
> plugin, that seems to work similiar.  If I went the route of just
> posting video (which I may, if I get tired of working on the complex)
> this would work great.  I'm also looked at django-syncr, which is
> similiar to what I am aiming for ...
>
> On Aug 27, 10:08 am, Bill Freeman  wrote:
> > Look at django-oembed.  A CharField will serve for every (supported)
> > provider.
> >
> > On Wed, Aug 26, 2009 at 8:17 PM, thornomad  wrote:
> >
> > > Hi - need some suggestions.
> >
> > > I am trying to put together an app that allows users to submit links
> > > to videos at popular video sharing sites (e.g., youtube, vimeo, etc)
> > > -- the links get submitted, data about the video (title, description,
> > > play count, etc) is collected from the respective site and populates
> > > model fields, and the video entry is queued for review.
> >
> > > Caveats: I would like to keep the original "synced" data in its own
> > > field and the "approved" data (as edited) in separate field.  I
> > > imagine that the data first gets brought into the "edit" field, admin
> > > may make changes and save, but the "originating" data will remain
> > > separate and continue to be updated (synced).
> >
> > > This means I need at least
> >
> > > I am stuck, though, on the most appropriate/logical approach to this
> > > app.  Some approaches I've considered.
> >
> > > [1] My first thought is to create base model "Video" (with the main
> > > fields) and then create child models like YoutubeVideo and VimeoVideo
> > > and BlipVideo ... when the user submits a url, would do a regex on it
> > > in the view, and send it through the appropriate child class.  I could
> > > then grab the base Video model in my views (not having to distinguish
> > > the type of video) and use a "leaf" technique (eg,
> > >http://www.djangosnippets.org/snippets/1031/) to run the child's
> > > "sync" or "update" command.  CONS: seems tacky and not easy to build
> > > on.  The leaf technique isn't working when I override the save()
> > > function in leaf models.
> >
> > > [2] Perhaps create only a single model and then create separate
> > > classes/functions to handle the the syncing of data based on the
> > > URLField data ... so, perhaps when Video.update() is called, it would
> > > run the logic then to see what kind of url it has, and how to update
> > > it.  CONS: I thought maybe I could just create a ForeignKey field to a
> > > non-model group of classes with common functions (update, sync,
> > > etc) ... but I am not sure how, or if, I can do that.
> >
> > > [3] Outsourcing.
> >
> > > Hope this makes sense and folks have some feedback about how they
> > > might approach this.  I would like this to be easily expandable -- for
> > > example, add YouTube and Vimeo support to start, and easily add other
> > > sites without having to "hack" it.
> >
> > > I know this is a huge question, but am interested in your "Design
> > > Approach" thoughts ...
> >
> > > Thanks,
> > > Damon
> --~--~-~--~~~---~--~~
> 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-us...@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=.




Re: wsgi config

2009-11-12 Thread Angel Cruz
Does it look like this now?  This should work:

Alias /media/ "C:/Program Files/Apache Software
Foundation/Apache2.2/htdocs/media/"


Order allow,deny
Allow from all



Alias /peergw/site_media/ "C:/Program Files/Apache Software
Foundation/Apache2.2/htdocs/site_media/"


Order allow,deny
Allow from all




Order deny,allow
Allow from all



On Wed, Nov 11, 2009 at 12:32 AM, knight  wrote:

>
> Hi,
>
> Thanks for the reply.It helps for the admin media.
> But my site_media (static files) still don't work.
> Do you have another idea what my problem is?
>
> Thanks, Arshavski Alexander.
>
> On Nov 11, 12:31 am, Angel Cruz  wrote:
> > Maybe the backslash is a problem.
> >
> > Here is how my media alias looks like:
> >
> > Alias /media/ "C:/Program Files/Apache Software
> > Foundation/Apache2.2/htdocs/django/media/"
> >  > Foundation/Apache2.2/htdocs/django/media/">
> > Order allow,deny
> > Allow from all
> > 
> >
> >
> >
> > On Sun, Nov 8, 2009 at 11:37 PM, knight  wrote:
> >
> > > Hi. I have a problem with configuring my django site with mod_wsgi.
> > > My httpd.conf is:
> >
> > > LoadModule wsgi_module modules/mod-wsgi.so
> > > WSGIScriptAlias /peergw C:/mxhw/mx30/django.wsgi
> >
> > > 
> > >Order deny,allow
> > >allow from all
> > > 
> >
> > > Alias /media/ "C:\Program Files\Apache Software Foundation
> > > \Apache2.2\htdocs\media"
> > > Alias /peergw/site_media/ "C:\Program Files\Apache Software Foundation
> > > \Apache2.2\htdocs\site_media"
> >
> > >  > > \Apache2.2\htdocs">
> > > Order deny,allow
> > > Allow from all
> > > 
> >
> > > I want my site to run on /peergw since I have many instances on the
> > > server and each one running with the different prefix.
> > > Everything works fine except all the images - I can't see static media
> > > files both in admin and my site.
> > > When I go to "/site_media//image" and not "/peergw/site_media//
> > > image", I do see the image.
> > > What am I doing wrong?
> > > By the way, I'm running on Vista, but I have the same problem on XP.
> >
> > > Thanks, Arshavski Alexander.
> --~--~-~--~~~---~--~~
> 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-us...@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=.




Can a model generate custom SQL when loading/saving a field?

2009-11-12 Thread Tony Czeh
I'm running into a bit of a problem with Django's models.  I have a
VARCHAR field that needs to be stored with the content AES_ENCRYPT
then HEXed (done on the MySQL server).

What I'd like to have happen is for the Django model to generate
"AES_DECRYPT(UNHEX(field), salt)" when the field is loded by the model
and "HEX(AES_ENCRYPT(field, salt))" when the field is saved by the
model.

Is there a way to make this happen, so far I'm not turning up
anything.

Cheers,
Tony Czeh

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: How to use French accent on django template?

2009-11-12 Thread Tom Evans
On Thu, Nov 12, 2009 at 4:30 PM, rebus_  wrote:

> 2009/11/12 NMarcu :
> > Hello all,
> >
> >   How to use French accent on django template? It's very strange. in
> > one template is working very well, but in other(templatetag) not, I
> > got this error:
> >
> > TemplateSyntaxError at /operators/ajax
> >
> > Caught an exception while rendering: 'ascii' codec can't encode
> > character u'\xe9' in position 2: ordinal not in range(128)
> >
> >
> > Do you have any idea what I'm doing wrong?
> > My template look like this:
> > {% load i18n %}
> > 
> >{{ column.caption }}
> >{% if column.href %}
> >Sort
> >{% endif %}
> >{% if column.filtered %}
> >(filtered)
> >{% endif %}
> > 
> >
> >  {{ column.caption }}  -> return a French word.
> >
> > --
>
> Is column.caption unicode string?
> Also does this happen when you call AJAX view or while rendering?
> Perhaps you need to explicitly set encoding of python source files by
> putting  # -*- coding: utf-8 -*- at the top of the file.
>

Clearly it isn't unicode - \xe9 is é in latin1/iso 8859-1.

Does this come from the database by any chance? Is the database mysql? If
so, is the default charset of the {db,connection,client} set to latin1?

Cheers

Tom

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Imports, works from directory but not from file

2009-11-12 Thread Bill Freeman
On Thu, Nov 12, 2009 at 10:33 AM, andreas schmid  wrote:
>>
> im on a unix system and i can import it on the django shell but it makes
> troubles when running the django server which doesnt make sense


It may be that it won't be recognized as an app because the app
directory doesn't
have a models.py file in it.  The app logic decides that an app listed
in settings.py
INSTALLED_APPS has a models.py.  I don't know off hand whether the test is made
by looking for that name in the directory, in which case your
configuration would fail,
by doing "import app.models" to see if it gets an exception, in which
case your code
passes, but your models wouldn't be available unless you put stuff in
app/models/__init__.py to import your other models files.

Bill

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: How to use French accent on django template?

2009-11-12 Thread rebus_
2009/11/12 NMarcu :
> Hello all,
>
>   How to use French accent on django template? It's very strange. in
> one template is working very well, but in other(templatetag) not, I
> got this error:
>
> TemplateSyntaxError at /operators/ajax
>
> Caught an exception while rendering: 'ascii' codec can't encode
> character u'\xe9' in position 2: ordinal not in range(128)
>
>
> Do you have any idea what I'm doing wrong?
> My template look like this:
> {% load i18n %}
> 
>    {{ column.caption }}
>    {% if column.href %}
>        Sort
>    {% endif %}
>    {% if column.filtered %}
>        (filtered)
>    {% endif %}
> 
>
>  {{ column.caption }}  -> return a French word.
>
> --

Is column.caption unicode string?
Also does this happen when you call AJAX view or while rendering?
Perhaps you need to explicitly set encoding of python source files by
putting  # -*- coding: utf-8 -*- at the top of the file.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: form with loop over fields?

2009-11-12 Thread Nick Arnett
On Wed, Nov 11, 2009 at 11:28 PM, andreas schmid wrote:

>
>
> ok this is fine for the form representation but how should i extend my
> model to define the field i am going to multiply 12 times a year for x
> years? (actually im using generic create_update view to get the form out
> of the model)
>
> and how should i store the values independently from each other?


I believe the simple way would be a model that has month and year fields,
with a meta method that defines them as unique together.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




How to use French accent on django template?

2009-11-12 Thread NMarcu
Hello all,

   How to use French accent on django template? It's very strange. in
one template is working very well, but in other(templatetag) not, I
got this error:

TemplateSyntaxError at /operators/ajax

Caught an exception while rendering: 'ascii' codec can't encode
character u'\xe9' in position 2: ordinal not in range(128)


Do you have any idea what I'm doing wrong?
My template look like this:
{% load i18n %}

{{ column.caption }}
{% if column.href %}
Sort
{% endif %}
{% if column.filtered %}
(filtered)
{% endif %}


 {{ column.caption }}  -> return a French word.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Imports, works from directory but not from file

2009-11-12 Thread rebus_
I am not sure if i got the problem right, but this is what i think you could do.

If you want to keep your views in directory:

app/
   views/
  __init__.py <- This is where you keep your views so you don't
even need to change your urls.py or anthing
  something_else.py <- something else

Also you can keep your models in models/__init__.py and don't need to
change any imports, like:

app/
   models/
  __init__.py <- this is where your keep your models

On the other hand you can have

app/
   models/
  other_models.py <- this is where the models are for example
  __init__.py <- this is where you import your models so they can
be imported

in __init__.py you say
from other_models import * (or Model1, Model2 etc)

And where every you used your models like
from app.models import Model still works as expected.

Same goes for views.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Increment a value in a database table field

2009-11-12 Thread Denis Bahati
Hi All,

I have a field with an integer value which needs to be incremented
every time any user updates its status within a week. If that week has
passed it should insert a new row. Now i was trying to figure out but
didn't get any concept on how to go through. Please any idea?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: How periodically import content to Django?

2009-11-12 Thread R. Gorman
If the file can be parsed you could setup a script to read the file
and use the get_or_create query to add new entries.

R.

On Nov 12, 10:31 am, bowlby  wrote:
> Is there a way to periodically import content to Django by means of
> uploading a file of some sort?
>
> The use case is this:
> There is a list of institutions. Each institution has a couple of
> programmes. Once or twice a year we get a file with all the programmes
> per institution which we want to use in our application. Is there
> already some tool that can look for entries (institutions or
> programmes) that are already present and otherwise add content?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Imports, works from directory but not from file

2009-11-12 Thread andreas schmid
Bill Freeman wrote:
> If that wasn't a typo, I suspect that you're going to have trouble
> with having a directory
> named "views.py".  
yes it was a typo... my dir is called 'views'
> I don't know how you import anything from it unless
> it is directly on
> your path.
>
> When you say "my app is in the pythonpath of the environment":
>1. Which directory is in the python path?
>   
my pythonpath is called 'site-packages' and this one is in the
pythonpath. every packages in there has an __init__.py in each subdir.
>2. If you mean that you've added it to the PYTHONPATH environment
> variable then
> please check whether you can find it in sys.path when running in the manage.py
> shell.  (If you don't know how to do that, please ask.)  I don't know
> if your on Windows
> or something else, but, especially on Windows, I don't take it for
> granted that environment
> settings will be properly respected/available.
>   
im on a unix system and i can import it on the django shell but it makes
troubles when running the django server which doesnt make sense
> Bill
>
> On Thu, Nov 12, 2009 at 2:39 AM, andreas schmid  wrote:
>   
>> Bill Freeman wrote:
>> 
>>> Does your project root (I'm assuming that's the directory containing
>>> the sub directory "app") have an __init__.py file.  Does the app
>>> directory?  I'm assuming that the one you mention below is in
>>> app/models/ .  All three are required, if what you have on your
>>> sys.path is just the project root.
>>>
>>>
>>>   
>> my app is in the pythonpath of the environment and every directory has
>> an __init__.py
>> everything worked fine till i changed the structure from:
>>
>> app/
>>__init__.py
>>models.py
>>views.py
>>urls.py
>>
>> to:
>>
>> app/
>>models/
>> __init__.py
>> models.py
>>views.py/
>> __init__.py
>> whatever.py
>> another.py
>>urls/
>> __init__.py
>> myurls.py
>> anotherurls.py
>> __init__.py
>>
>> so it doesnt really make sense that i cant import something in the
>> second case from my point of view.
>>
>>
>> 
>>> Do make sure that your project root is on your sys.path.  You can do
>>> that by temporarily adding:
>>>
>>> import foo
>>>
>>> to settings.py, and creating a file foo.py in the project root containing, 
>>> say:
>>>
>>> print "Foo!"
>>>
>>> and then do:
>>>
>>> python manage.py shell
>>>
>>> As part of the startup printout you should get a line containing only:
>>>
>>> Foo!
>>>
>>> By the way, I'm pretty sure that lots of django internal machinery,
>>> like syncdb, for example, depends on there being a file named exactly
>>> "models.py" in each app.  So a better choice of directory structure
>>> might be "app/myapp/models.py", with your myclass class in the
>>> models.py file.  Pinax uses such a structure, though the upper
>>> directory is called apps instead of app (there may be more than one)
>>> and has been added to the path, so that you can mention it in
>>> INSTALLED_APPS as just 'myapp', rather than 'apps/myapp'.  If you go
>>> this route, you will want to insert the apps directory at or near the
>>> beginning of sys.path, rather than appending it, so that when you
>>> mention a possibly installed app, such as django_microblogging, but
>>> which you have customized in a copy in your apps folder, you can say
>>> 'microblogging' in your INSTALLED_APPS and it will find yours rather
>>> than the system version.  (TN.B.: emplate paths are a separate issue.)
>>>
>>> Bill
>>>
>>> On Wed, Nov 11, 2009 at 10:34 AM, andreas schmid  
>>> wrote:
>>>
>>>   
 im experiencing the same problem.
 i started with a simple app and the modules.py was at the root of the
 app package, so everything was fine.
 now i extended the app and restructured the files in it by making a
 subfolder app/models and inside an __init__.py and the mymodel.py

 in the urls.py which i have an import like
 from app.models.mymodel import myclass

 and while the django shell is able to import it without any problem the
 django server isnt. im using buildout to build the whole django
 environment so the python interpreter im starting the shell and the one
 of the server is the same.

 i already tried to remove all .pyc and start everything again but i had
 no luck.

 this is weird and i cant figure out what the problem could be.



 Bill Freeman wrote:

 
> I had another couple of thoughts.
>
> In the manage.py shell, try:
>
> from openid.yadis import xri
> xri
>
> The output will include from where it got xri.  Make sure that it's
> coming from your lib directory, and not from some old system wide
> installation of openid.
>
>
> Instead of:
>
> from openid.association import Association as OIDAssociation
>
> try:
>
>

How periodically import content to Django?

2009-11-12 Thread bowlby
Is there a way to periodically import content to Django by means of
uploading a file of some sort?

The use case is this:
There is a list of institutions. Each institution has a couple of
programmes. Once or twice a year we get a file with all the programmes
per institution which we want to use in our application. Is there
already some tool that can look for entries (institutions or
programmes) that are already present and otherwise add content?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Imports, works from directory but not from file

2009-11-12 Thread Bill Freeman
If that wasn't a typo, I suspect that you're going to have trouble
with having a directory
named "views.py".  I don't know how you import anything from it unless
it is directly on
your path.

When you say "my app is in the pythonpath of the environment":
   1. Which directory is in the python path?
   2. If you mean that you've added it to the PYTHONPATH environment
variable then
please check whether you can find it in sys.path when running in the manage.py
shell.  (If you don't know how to do that, please ask.)  I don't know
if your on Windows
or something else, but, especially on Windows, I don't take it for
granted that environment
settings will be properly respected/available.

Bill

On Thu, Nov 12, 2009 at 2:39 AM, andreas schmid  wrote:
> Bill Freeman wrote:
>> Does your project root (I'm assuming that's the directory containing
>> the sub directory "app") have an __init__.py file.  Does the app
>> directory?  I'm assuming that the one you mention below is in
>> app/models/ .  All three are required, if what you have on your
>> sys.path is just the project root.
>>
>>
> my app is in the pythonpath of the environment and every directory has
> an __init__.py
> everything worked fine till i changed the structure from:
>
> app/
>    __init__.py
>    models.py
>    views.py
>    urls.py
>
> to:
>
> app/
>    models/
>             __init__.py
>             models.py
>    views.py/
>             __init__.py
>             whatever.py
>             another.py
>    urls/
>             __init__.py
>             myurls.py
>             anotherurls.py
> __init__.py
>
> so it doesnt really make sense that i cant import something in the
> second case from my point of view.
>
>
>> Do make sure that your project root is on your sys.path.  You can do
>> that by temporarily adding:
>>
>>     import foo
>>
>> to settings.py, and creating a file foo.py in the project root containing, 
>> say:
>>
>>     print "Foo!"
>>
>> and then do:
>>
>>     python manage.py shell
>>
>> As part of the startup printout you should get a line containing only:
>>
>>     Foo!
>>
>> By the way, I'm pretty sure that lots of django internal machinery,
>> like syncdb, for example, depends on there being a file named exactly
>> "models.py" in each app.  So a better choice of directory structure
>> might be "app/myapp/models.py", with your myclass class in the
>> models.py file.  Pinax uses such a structure, though the upper
>> directory is called apps instead of app (there may be more than one)
>> and has been added to the path, so that you can mention it in
>> INSTALLED_APPS as just 'myapp', rather than 'apps/myapp'.  If you go
>> this route, you will want to insert the apps directory at or near the
>> beginning of sys.path, rather than appending it, so that when you
>> mention a possibly installed app, such as django_microblogging, but
>> which you have customized in a copy in your apps folder, you can say
>> 'microblogging' in your INSTALLED_APPS and it will find yours rather
>> than the system version.  (TN.B.: emplate paths are a separate issue.)
>>
>> Bill
>>
>> On Wed, Nov 11, 2009 at 10:34 AM, andreas schmid  
>> wrote:
>>
>>> im experiencing the same problem.
>>> i started with a simple app and the modules.py was at the root of the
>>> app package, so everything was fine.
>>> now i extended the app and restructured the files in it by making a
>>> subfolder app/models and inside an __init__.py and the mymodel.py
>>>
>>> in the urls.py which i have an import like
>>> from app.models.mymodel import myclass
>>>
>>> and while the django shell is able to import it without any problem the
>>> django server isnt. im using buildout to build the whole django
>>> environment so the python interpreter im starting the shell and the one
>>> of the server is the same.
>>>
>>> i already tried to remove all .pyc and start everything again but i had
>>> no luck.
>>>
>>> this is weird and i cant figure out what the problem could be.
>>>
>>>
>>>
>>> Bill Freeman wrote:
>>>
 I had another couple of thoughts.

 In the manage.py shell, try:

     from openid.yadis import xri
     xri

 The output will include from where it got xri.  Make sure that it's
 coming from your lib directory, and not from some old system wide
 installation of openid.


 Instead of:

     from openid.association import Association as OIDAssociation

 try:

     from association import Association as OIDAssociation


 Also, expecially if the previous worked, in your settings.py, instead of:

     sys.path.append(os.path.join(FILE_ROOT, 'lib', 'openid'))

 try

     sys.path.append(os.path.join(FILE_ROOT, 'lib'))

 Bill



>>>
>>
>> --~--~-~--~~~---~--~~
>> 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
>

QuerySet Question

2009-11-12 Thread Chris
Hi all,

I am new to Django and I am having a little trouble.

The situation:
I am setting up a music selling website (similar to iTunes) for a uni
project. There are Tracks, Albums and Artists as well as users via
Django auth. A user can own a track. This is accomplished with a many
to many field in the Track model (owners = models.ManyToManyField
(User)).

The problem:
I want to put an "owned" tick next to each track that the user owns
throughout the site.

I cannot put a function in the Track class to return whether the
current user owns the track or not because track does not have access
to the user details (request.user).

I could return another data set with the same indices as the tracks
and have it store a boolean to indicate whether the current user owns
the track or not. Something along the lines of "owner[i] = tracks
[i].owners.filter(username__exact=request.user.username).count()".
Alternatively, do something like "Track.objects.extra(select={'owned':
"1"})" with some logic in there to figure out if it should be 1 or 0
(anyone know how to do something like that???). The trouble with
either of these methods, aside from not being very elegant, is that I
don't always just pass a tracks QuerySet to a template. I often pass
an albums QuerySet or an artists QuerySet, both of which are also used
to access tracks. For the case of a set of albums I would need to
iterate over all of them, iterate over all of their tracks and store
which tracks are owned in a 2D array. For the case of a set of artists
I would need to iterate over all of them, iterate over all their
albums, iterate over all of their tracks and store which ones are
owned in a 3D array. There has got to be a better way than this.

Is there a way of getting a model function to access user details so
that I can do a simple "if track.owned" in the template? Is there a
better solution to doing it in the view? Is there something I have not
thought of? What would be the "best practice" solution to this?

Thanks in advance for your 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-us...@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=.




Re: forms.ChoiceField and empty values

2009-11-12 Thread rebus_
2009/11/12 Monika Sulik :
> As I haven't had any replies so far, I'll add some more information...
>
> The empty label appears if I redefine the form like this:
>
> class CompetitionSearchForm(forms.ModelForm):
>    class Meta:
>        model = Competition
>        fields = ('name','type')
>
> It disappears again if I make the changes I need to on the fields
> (i.e. "unrequire" them):
>
> class CompetitionSearchForm(forms.ModelForm):
>    name = forms.CharField(required=False)
>    type = forms.ChoiceField(choices=COMPETITION_TYPE_CHOICES,
> required=False)
>    class Meta:
>        model = Competition
>        fields = ('name','type')
>
> Should I be defining my type field somehow differently? Or is this a
> bug in Django that I should report?
>

What does model Competition look like?
Do you have choices defined in your models.py and use choices argument
when creating that field in models?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Model validation

2009-11-12 Thread rebus_
2009/11/12 Dirk Uys :
> On Thu, Nov 12, 2009 at 2:23 PM, rebus_  wrote:
>
>>
>> You can add custom clean methods in your form:
>>
>> class Event (models.Model):
>>    start_date = models.DateField()
>>    end_date = models.DateField()
>>
>>   def clean(self):
>>       start = self.cleaned_data.get('start_date', False)
>>       end = self.cleaned_data.get('end_date', False)
>>       if not start or not end:
>>          raise forms.ValidationError('message')
>>       if start > end:
>>          raise forms.ValidationError('start is greater then end')
>>       return self.cleaned_data
>>
>> This is just an example code.
>>
>> Using this approach validation errors will not be associated with and
>> field.
>> You could write clean_start_date and clean_end_date methods which
>> would evaluate each field and all validation errors would be
>> associated with specific field.
>>
>> To learn more about form validation read [1] or [2]:
>>
>> [1] http://docs.djangoproject.com/en/dev/ref/forms/validation/
>> [2]
>> http://code.djangoproject.com/browser/django/trunk/docs/ref/forms/validation.txt
>>
>
> Thanks! This is actually what I have done. The only problem is that I do not
> always use forms to supply data (sometimes I import from CVS) and would like
> to avoid doing the validation at two different points.
>
> For the time being, I guess this will do
>
> Cheers
> Dirk
>

Technically, i think you should be able iterate over dataset imported
from CVS and bound each data row to form, validate the form and then
use the cleaned_data to create an object of the Model and save it or
whatever. Not sure what performance impacts this would have, if any,
but i guess that would depend on the amount of data that needs
validation.

Take a look at [1] forms API for example.

Also you could factor out the clean code into standalone function for
example and then use that function to validate the given data both in
form and the place you use imported data.

But then again i am no guru on the subject, these are just my opinions.

[1] http://docs.djangoproject.com/en/dev/ref/forms/api/

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Switching a Models Field Class at Runtime

2009-11-12 Thread Sean Brant
Yeah that would work. I'd like to avoid that because every Item will
need its child content, so you would have to always use a join (which
are slow).

One more thought is it possible to has multiple models that all save
to the same table? I only really need the helpful Image and File
fields for writing, I can do all my reads from a base model.

Sean

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: forms.ChoiceField and empty values

2009-11-12 Thread Monika Sulik
As I haven't had any replies so far, I'll add some more information...

The empty label appears if I redefine the form like this:

class CompetitionSearchForm(forms.ModelForm):
class Meta:
model = Competition
fields = ('name','type')

It disappears again if I make the changes I need to on the fields
(i.e. "unrequire" them):

class CompetitionSearchForm(forms.ModelForm):
name = forms.CharField(required=False)
type = forms.ChoiceField(choices=COMPETITION_TYPE_CHOICES,
required=False)
class Meta:
model = Competition
fields = ('name','type')

Should I be defining my type field somehow differently? Or is this a
bug in Django that I should report?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: forms.ChoiceField and empty values

2009-11-12 Thread Monika Sulik
As I haven't had any replies so far, I'll add some more information...

The empty label appears if I redefine the form like this:

class CompetitionSearchForm(forms.ModelForm):
class Meta:
model = Competition
fields = ('name','type')

It disappears again if I make the changes I need to on the fields
(i.e. "unrequire" them):

class CompetitionSearchForm(forms.ModelForm):
name = forms.CharField(required=False)
type = forms.ChoiceField(choices=COMPETITION_TYPE_CHOICES,
required=False)
class Meta:
model = Competition
fields = ('name','type')

Should I be defining my type field somehow differently? Or is this a
bug in Django that I should report?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Model validation

2009-11-12 Thread Dirk Uys
On Thu, Nov 12, 2009 at 2:23 PM, rebus_  wrote:


> You can add custom clean methods in your form:
>
> class Event (models.Model):
>start_date = models.DateField()
>end_date = models.DateField()
>
>def clean(self):
>   start = self.cleaned_data.get('start_date', False)
>   end = self.cleaned_data.get('end_date', False)
>   if not start or not end:
>  raise forms.ValidationError('message')
>   if start > end:
>  raise forms.ValidationError('start is greater then end')
>   return self.cleaned_data
>
> This is just an example code.
>
> Using this approach validation errors will not be associated with and
> field.
> You could write clean_start_date and clean_end_date methods which
> would evaluate each field and all validation errors would be
> associated with specific field.
>
> To learn more about form validation read [1] or [2]:
>
> [1] http://docs.djangoproject.com/en/dev/ref/forms/validation/
> [2]
> http://code.djangoproject.com/browser/django/trunk/docs/ref/forms/validation.txt
>
>
Thanks! This is actually what I have done. The only problem is that I do not
always use forms to supply data (sometimes I import from CVS) and would like
to avoid doing the validation at two different points.

For the time being, I guess this will do

Cheers
Dirk

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: URLs and masking of private objects

2009-11-12 Thread Steinar Rune Eriksen
Thanks for your suggestions. As said, I would surely have underlying
security to actually protect the private data at the object level. My
questions was simply to make the URLs look less object like (in order
to make naiv users feel more safe as well). Using slugs/GUIDs seems to
be a way forward.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Making the case for Django (vs. Drupal)

2009-11-12 Thread Ray
On Nov 12, 11:16 am, shacker  wrote:
> I just wanted to thank everyone for their excellent contributions to
> this thread. Sorry I got side-tracked for a while. I've just put up a
> pretty complete draft of a post on this topic, written with decision
> makers (managers, supervisors) in mind. It's still probably somewhat
> technical for that group, but that's the nature of the topic.
>
> http://birdhouse.org/blog/2009/11/11/drupal-or-django/
>

Hi Scot,

You should probably send a link over to the Drupal forum as well to
get some feedback from the other side of the fence.

To sum it up, anyone who is good developer and experienced in either
platform will probably produce very similar results in a similar
timeframe.

It really comes down to:

"do you (or your department) want to write code in PHP or Python"

because unless you have hugely complex or popular sites, either would
work quite comfortably.

Regards,

Ray Smith

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: View using 2 models

2009-11-12 Thread EmileZola
Well, I missed the point apparently. I was unaware django created
reverse attribute for ForeignKey. Thanks !

On Nov 12, 5:44 am, bruno desthuilliers
 wrote:
> On 12 nov, 07:07, EmileZola  wrote:
>
>
>
> > Alright, I'm pretty new to Django and I've got this problem I can't
> > quite solve.
>
> > I basically have two models, wich I use to put blog articles into
> > categories. One is a Category and the other is a Subject. So in my
> > categories I might have ('Programming', 'Music', 'Essays') and my
> > subjects are listed under those various categories. So under
> > Programming I might have ('Python', 'PHP', 'ASM').
>
> > Here a stripped down version of my models :
>
> > class Category(models.Model):
> > name = models.CharField(_('Categorie'), max_length=100)
>
> > class Subject(models.Model):
> > name = models.CharField(_('Forum'), max_length=100)
> > description = models.CharField(_('Description'), max_length=250)
> > category = models.ForeignKey(Category)
>
> > Now, what I try to do in my view, is to loop through the categories
> > and list each subject it contains. Someone can help me ?
>
> Why do you want to do this in the view ??? If it's for rendering
> purpose - which I guess is the case - just pass the appropriate
> Category queryset to your context, then do the loop in the template,
> ie:
>
> # yourapp/views.py
>
> def category_list(request, ...):
>    context = dict(categories = Category.objects.all().select_related
> ())
>    return render_to_response(
>       "yourapp/category_list.html",
>       context,
>       context_instance=RequestContext(request)
>       )
>
> # yourapp/category_list.html
>
> 
> {% for category in categories %}
>   
>     {{ category.name }}
>     
>     {% for subject in category.subject_set.all %}
>       {{ subject.name }}
>     {% endfor %}
>     
>   
> {% endfor %}
> 
>
> HTH - Or did I miss the point ?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: URLs and masking of private objects

2009-11-12 Thread Steinar Rune Eriksen
Thanks for the feedback. Yes I do implement object level security (so
not security by obscurity), but just wanted to make it less object ID
lookalike to the naive user (who may feel that the system is not
secure). Slugs with GUID seems like a good option.

Steinar

On Nov 12, 12:38 pm, Mike Ramirez  wrote:
> On Thursday 12 November 2009 02:48:35 Mike Ramirez wrote:> urlpatterns = 
> patterns('', url(r'^portfolios/(?P[\w-]+$',
> > 'portfolio.views.load_details', name='details'),
>
> Typo fixes:
> urlpatterns += patterns('', url(r'^portfolios/(?P[\w-]+)$',  
> 'portfolio.views.load_details', name='details'), )
>
> --
> "An open mind has but one disadvantage: it collects dirt."
> -- a saying at RPI
>
>  signature.asc
> < 1KViewDownload

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Can I change the restriction on "username" without breaking anything?

2009-11-12 Thread Richard E. Cooke
Thanks.  Sorry.  I have got to stop posting when I'm tired...

For punishment, I read the Wikipedia article on the "@" character:
http://en.wikipedia.org/wiki/@

No, I did not do a google search because I ass-umed the truly relevant
info would be in this list.  really.

The first Google hit is a Django snippet, and while the solution might
not be global like I want it does point out a potential problem.  In
that there already is an e-mail field and having duplicate data in the
two fields could break some applications.

Which makes me wonder if the "right" way is to use a custom user
validation system, likely with the e-mail field dropped, or maybe just
aliased to the username so things that expect e-mail address find one.


--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Switching a Models Field Class at Runtime

2009-11-12 Thread Mike Ramirez
On Thursday 12 November 2009 06:05:00 Sean Brant wrote:
> Let me start out by saying this feels a little over engineered but I
> wanted to see what people thought anyways.
> 
> I would like to create a list similar to a Facebook wall. You can post
> stuff and attach content to the post. In the past I have create a
> table with properties for all content formats and only set the one I
> was interested in. Thats bad cause you have all these empty fields for
> no reason. I have also just created foreign key to a separate content
> model (one for each format). That means you have to joins all the
> time. Since at the end of the day all of these formats are stored as
> strings, I can just use ONE content field. However I lose all the nice
> Image and File handling stuff Django gives you. So what if there was a
> ModelField that could change itself at runtime. Would I be better of
> doing this feature in a non-relational database and handling all the
> file upload stuff myself?
> 
> All content will be represented in the database as a VARCHAR. I'll add
> some pseudo code that might explain it better than i can.
> 
> choices = (
> (0, 'note'),
> (1, 'link'),
> (2, 'image'),
> )
> 
> formats = (
> (0, models.CharField, {'max_length': 200}),
> (1, models.UrlField,),
> (2, models.ImageField, {'upload_to': 'uploads'),
> )
> 
> class Item(models.Model):
> title = models.CharField(max_length=200)
> format = models.IntegerField(choices=choices, default=0)
> content = MultiFormatField(formats=formats, format_field='format')
> # changes based on instance.format
> 
> Thanks for taking the time to read this over.
> 
> - Sean
> 
> --
How would generic.GenericForeignKey fit your needs?

http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1

Mikr


Bringing computers into the home won't change either one, but may
revitalize the corner saloon.


signature.asc
Description: This is a digitally signed message part.


Switching a Models Field Class at Runtime

2009-11-12 Thread Sean Brant
Let me start out by saying this feels a little over engineered but I
wanted to see what people thought anyways.

I would like to create a list similar to a Facebook wall. You can post
stuff and attach content to the post. In the past I have create a
table with properties for all content formats and only set the one I
was interested in. Thats bad cause you have all these empty fields for
no reason. I have also just created foreign key to a separate content
model (one for each format). That means you have to joins all the
time. Since at the end of the day all of these formats are stored as
strings, I can just use ONE content field. However I lose all the nice
Image and File handling stuff Django gives you. So what if there was a
ModelField that could change itself at runtime. Would I be better of
doing this feature in a non-relational database and handling all the
file upload stuff myself?

All content will be represented in the database as a VARCHAR. I'll add
some pseudo code that might explain it better than i can.

choices = (
(0, 'note'),
(1, 'link'),
(2, 'image'),
)

formats = (
(0, models.CharField, {'max_length': 200}),
(1, models.UrlField,),
(2, models.ImageField, {'upload_to': 'uploads'),
)

class Item(models.Model):
title = models.CharField(max_length=200)
format = models.IntegerField(choices=choices, default=0)
content = MultiFormatField(formats=formats, format_field='format')
# changes based on instance.format

Thanks for taking the time to read this over.

- Sean

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Template conceptual help

2009-11-12 Thread Maksymus007
> Yeps, I just knew I had already seens something like that
> somewhere !-)
>
> Ok, problem solved then.

yep :)

>
>> Your solution is way cool, but again, its violates DRY -
>> additional code in every view (can be probably ommited by decorators,
>
> Indeed.
>
>> but still, the same decorator for every view  ;) )
>
> Yeps, I know. But it's the best solution I could came with within the
> 5 minutes I had to solve the problem - and it can eventually solve
> other problems that xextends could not (well, eventually, really - no
> concrete example at hand ATM)

I think that a bit more control over templates - like possibility to
render some template with filled blocks into another block and simple
- some params form URLs directly in the templates - like sections
names, titles would suit there.
Nevertheless, thanks for 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-us...@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=.




Re: Template conceptual help

2009-11-12 Thread bruno desthuilliers


On 12 nov, 14:01, Maksymus007  wrote:
(snip)

> Well, yes, messages,html can be split into several files and then
> app_messages.html can include them in order. But then every
> app_messages.html must include them, which, in fact, is just
> copy-paste messages.html with different {%extends %}
> all I needed was to include a string within extended template and I
> foundhttp://www.djangosnippets.org/snippets/447/which, despite its
> age, worked (some changes were needed to have variables properly
> handeled, but well) like a charm.
>
> Then in app_messages.html i got:
>
> {% load xextends %}
> {% xextends "messages/messages.html" with parent="app/app.html" %} -
> which points to my additional frame with tabs, etc. Exactly what i
> wanted.

Yeps, I just knew I had already seens something like that
somewhere !-)

Ok, problem solved then.

> Your solution is way cool, but again, its violates DRY -
> additional code in every view (can be probably ommited by decorators,

Indeed.

> but still, the same decorator for every view  ;) )

Yeps, I know. But it's the best solution I could came with within the
5 minutes I had to solve the problem - and it can eventually solve
other problems that xextends could not (well, eventually, really - no
concrete example at hand ATM)

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Making the case for Django (vs. Drupal)

2009-11-12 Thread Nick Lo
Hi Scot

> I just wanted to thank everyone for their excellent contributions to
> this thread. Sorry I got side-tracked for a while. I've just put up a
> pretty complete draft of a post on this topic, written with decision
> makers (managers, supervisors) in mind. It's still probably somewhat
> technical for that group, but that's the nature of the topic.

Having held your post in my browser for most of a busy day I finally read it 
but wondered throughout who it was targeted at. Now I come back to this thread 
I still wonder. When you say "managers" and "supervisors" you don't indicate 
their level of technical knowledge or involvement. Your post suggests they ARE 
technically minded and involved and sells your argument from that perspective. 
If however they aren't then I think there is one angle it seems to ignore: If 
we picture that one focus in any managers agenda is "are the things that need 
to get done getting done so I can answer to my higher 
uppers/clients/customers/etc?"

I can of course only speculate here, but I imagine that the appeal of Drupal 
you are trying to compete against is that, from their perspective, in going 
from 0-60, Drupal appears to already be at 50. It really doesn't matter to them 
that it could have taken 4 times as long to get from 0-50 as it would have 
taken if Django was used. To them the tangible is where Drupal is now.

It's also a jump to be able to realise that the 50-60 bit takes even longer and 
may actually never quite get there with a pre-existing solution. Your post 
almost deepens the sense that yeah, Django may be great but it's at 0 and as a 
manager I have to put ALL my trust in you that you're right. Partly because all 
those things Drupal already has I don't have either the time or knowledge, or 
both, to manage the development of anyway.

With that in mind I think you need to start at a more comparable point to 
Drupal. It has loads of solutions already built that actually DO work together 
which you don't mention. Drupal is a CMS so why not refer to existing CMS apps 
or better, let NASA do it for you:

http://pydanny.blogspot.com/2009/11/picking-django-powered-cms.html

There is one point that you made that you should push a lot more, albeit a 
little differently: "In Django, all development starts by defining the data 
models that describe the organization, publication, or site.". That single 
point is huge for an organization; Compared to a pre-existing solution Django 
is used to build something that fits the organization not the other way round.

Where I think you need to reword is that you say "starts by". Does the manager 
really know where the start is? Do they picture a blank page with a blinking 
cursor? Of course they'd be nervous if that is what they see. You and the rest 
of us on this list know of course that Django is itself already very well 
equipped and what it doesn't contain it has an ever increasing list of 3rd 
party solutions that can be used even if temporarily.

I could probably go on but I think I need to let sleep have it's way for a 
change!

Cheers,

Nick


--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: AssertionError: Response didn't redirect as expected: Response code was 200 (expected 302)

2009-11-12 Thread Eesti Mate
You hit that nail square on the head :-) the fixture was broken.

Thank you, Preston!

E.

On Wed, 2009-11-11 at 18:07 -0800, Preston Holmes wrote:
> Does your fixture result in a valid form?
> 
> if the form.is_valid() line doesn't pass, then you would get a 200
> from the render to response...
> 
> -Preston
> 
> 
> On Nov 11, 4:38 pm, Eesti Mate  wrote:
> > When I'm testing my form with assertRedirects I get the following error 
> > message:
> >
> > AssertionError: Response didn't redirect as expected: Response code was 200 
> > (expected 302)
> >
> > Don't know what/when/where went wrong. It seems that I'm missing some 
> > crucial point(s).
> >
> > Thanks for your pointers & your time!
> > Eesti
> >
> > Here are the relevant lines of test.py, views.py, urls.py and the 
> > 'runserver' output (when I run the app):
> >
> > #tests.py:
> > r = self.client.post(reverse('example_form'), example_form_fixture)
> > self.assertRedirects(r, reverse('form_redirection'))
> >
> > #views.py:
> > def example_form_view(request):
> > if request.method == 'POST':
> > form = example_form(request.POST)
> > if form.is_valid():
> > form.save()
> > return 
> > HttpResponseRedirect(reverse('form_redirection'))
> > else:
> > form = example_form()
> > return render_to_response('example_form/example_form.html', 
> > {'form': form})
> >
> > def form_redirection_view(request):
> > return render_to_response('example_form/form_redirection_page.html')
> >
> > #example_form/urls.py:
> > urlpatterns = patterns('',
> > url(r'^example_form/$', 
> > 'sandbox.example_form.views.example_form_view', name='example_form'),
> > url(r'^form_redirection/$', 
> > 'sandbox.example_form.views.form_redirection_view', 
> > name='form_redirection'))  
> >
> > #'runserver':
> > Django version 1.1.1, using settings 'sandbox.settings'
> > Development server is running athttp://127.0.0.1:8000/
> > Quit the server with CONTROL-C.
> > [12/Nov/2009 01:25:38] "POST /example_form/example_form/ HTTP/1.1" 302 0
> > [12/Nov/2009 01:25:38] "GET /example_form/form_redirection/ HTTP/1.1" 200 60
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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=.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Template conceptual help

2009-11-12 Thread Maksymus007
On Thu, Nov 12, 2009 at 1:31 PM, bruno desthuilliers
 wrote:
> On 12 nov, 12:16, Maksymus007  wrote:
>> I have some problem with templates and separating templates blocks.
>>
>> There is a list of messages. Some properties are common, some are
>> application specific.
>> Properties are just html columns :)
>>
>> I got following templates
>> main.html -> basic "frame", which consists of common html, headers, scripts 
>> etc.
>> frame.html - which introduce additional division - tabs and content,
>> extends main.html
>>
>> app_specific.html - app specific tab lists - extends frame.html
>>
>> messages.html - common message list, which contains common properties
>> and block in the middle to add custom properites, extends
>> app_specific.html to be part of app, with proper tabs etc.
>>
>> app_msg.html - additional properties for messages list, extends 
>> messages.html.
>
>
> This indeed makes quite a few layers. But anyway...
>
>> My problem is - i need different app_specific.html for different
>> app_msg.html
>
> Hmmm... Then I'm not sure your layering scheme is appropriate. Do not
> forget that while pretty cool, template inheritance is by no mean the
> only way to factor out / reuse template code. You also have simple
> inclusions and custom templatetags. It's hard to tell without reading
> your code, but it might be possible that getting the "message.html"
> layer out of the inheritance tree and refactoring it as an inclusion
> or custom templatetag solve your problem. If not:
>
>> - is there any way I can achieve that without using
>> variables from view like context['app_specific_frame'] =
>> 'someapp.html' ?
>
> You can't put *anything* before an extends Node, anything in a "child"
> template that's outside a block Node will be just ignored - even if
> it's just a "context extending" node [1] - and there's AFAIK no way to
> pass additional context thru the extends templatetag|2]. So this leave
> you with passing these "params" thru the context, one way or another
> (cf below).
>
> [1] I posted about this on the dev list last year or so - I had a
> working patch but well, I managed to solve my "problem" differently
> (and more cleanly IMHO) so I finally didn't bother opening a ticket
> and submitting the patch.
>
> [2] but while we're at it, I think I once saw some "better extends"
> templatetag somewhere - and well (thinking out loud), FWIW it should
> not be that hard to implement an "extended extends" tag that could
> takes more arguments...
>
>> I want to keep clear line between view and
>> controller.
>
> A bit OT, but in Django, you have views and templates - no
> controllers. But let's not waste time about terminology
> issues !-)
>
> I recently solved a more or less similar (even if probably way
> simpler) problem using the "kwargs" argument to url patterns.
>
> My problem was to pass additional per view project-specific context
> stuff to the templates - stuff that the app's views shouldn't be aware
> of, and that was not necessarily fitted for a ContextProcessor (like,
> which section of the main menu was to be 'hilited' for a given view,
> etc).
>
>
> The solution looks like this (simplified):
>
> 1/ in the project's urls.py, override the app's default urls and pass
> the extra context:
>
> urlpatterns = patterns('',
>    url("^some/pattern/(?P\d+)/$"
>        "app.some_view",
>        name="app_view_name",
>        # project specific extra context here:
>        kwargs={'extra_context':{'active_section_name'}}
>        ),
>     ...
> )
>
> 2/ in the app's views.py:
>
> def some_view(request, model_id, **kwargs):
>   context = dict()
>   # take care of eventual extra context, but without
>   # assuming anything about it:
>   extra_context = kwargs.get("extra_context", None)
>   if extra_context:
>      context.update(extra_context)
>
>   # then proceed as usual to setup the context, render to response
> etc...
>   # normal view code here
>
>
> This of course requires having full control on the app's views (or
> being willing and able to fork the app), but hey, it really helps
> making the app's views code "project-agnostic" for a very low cost.
>
> Don't know if this (or anything else in this post) can be a solution
> to your actual problem, but HTH nonetheless !-)

Well, yes, messages,html can be split into several files and then
app_messages.html can include them in order. But then every
app_messages.html must include them, which, in fact, is just
copy-paste messages.html with different {%extends %}
all I needed was to include a string within extended template and I
found http://www.djangosnippets.org/snippets/447/ which, despite its
age, worked (some changes were needed to have variables properly
handeled, but well) like a charm.
Then in app_messages.html i got:

{% load xextends %}
{% xextends "messages/messages.html" with parent="app/app.html" %} -
which points to my additional frame with tabs, etc. Exactly what i
wanted. Your solution is way cool, but again, its violates DRY -
additiona

Re: Template conceptual help

2009-11-12 Thread bruno desthuilliers
On 12 nov, 12:16, Maksymus007  wrote:
> I have some problem with templates and separating templates blocks.
>
> There is a list of messages. Some properties are common, some are
> application specific.
> Properties are just html columns :)
>
> I got following templates
> main.html -> basic "frame", which consists of common html, headers, scripts 
> etc.
> frame.html - which introduce additional division - tabs and content,
> extends main.html
>
> app_specific.html - app specific tab lists - extends frame.html
>
> messages.html - common message list, which contains common properties
> and block in the middle to add custom properites, extends
> app_specific.html to be part of app, with proper tabs etc.
>
> app_msg.html - additional properties for messages list, extends messages.html.


This indeed makes quite a few layers. But anyway...

> My problem is - i need different app_specific.html for different
> app_msg.html

Hmmm... Then I'm not sure your layering scheme is appropriate. Do not
forget that while pretty cool, template inheritance is by no mean the
only way to factor out / reuse template code. You also have simple
inclusions and custom templatetags. It's hard to tell without reading
your code, but it might be possible that getting the "message.html"
layer out of the inheritance tree and refactoring it as an inclusion
or custom templatetag solve your problem. If not:

> - is there any way I can achieve that without using
> variables from view like context['app_specific_frame'] =
> 'someapp.html' ?

You can't put *anything* before an extends Node, anything in a "child"
template that's outside a block Node will be just ignored - even if
it's just a "context extending" node [1] - and there's AFAIK no way to
pass additional context thru the extends templatetag|2]. So this leave
you with passing these "params" thru the context, one way or another
(cf below).

[1] I posted about this on the dev list last year or so - I had a
working patch but well, I managed to solve my "problem" differently
(and more cleanly IMHO) so I finally didn't bother opening a ticket
and submitting the patch.

[2] but while we're at it, I think I once saw some "better extends"
templatetag somewhere - and well (thinking out loud), FWIW it should
not be that hard to implement an "extended extends" tag that could
takes more arguments...

> I want to keep clear line between view and
> controller.

A bit OT, but in Django, you have views and templates - no
controllers. But let's not waste time about terminology
issues !-)

I recently solved a more or less similar (even if probably way
simpler) problem using the "kwargs" argument to url patterns.

My problem was to pass additional per view project-specific context
stuff to the templates - stuff that the app's views shouldn't be aware
of, and that was not necessarily fitted for a ContextProcessor (like,
which section of the main menu was to be 'hilited' for a given view,
etc).


The solution looks like this (simplified):

1/ in the project's urls.py, override the app's default urls and pass
the extra context:

urlpatterns = patterns('',
url("^some/pattern/(?P\d+)/$"
"app.some_view",
name="app_view_name",
# project specific extra context here:
kwargs={'extra_context':{'active_section_name'}}
),
 ...
)

2/ in the app's views.py:

def some_view(request, model_id, **kwargs):
   context = dict()
   # take care of eventual extra context, but without
   # assuming anything about it:
   extra_context = kwargs.get("extra_context", None)
   if extra_context:
  context.update(extra_context)

   # then proceed as usual to setup the context, render to response
etc...
   # normal view code here


This of course requires having full control on the app's views (or
being willing and able to fork the app), but hey, it really helps
making the app's views code "project-agnostic" for a very low cost.

Don't know if this (or anything else in this post) can be a solution
to your actual problem, but HTH nonetheless !-)

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Model validation

2009-11-12 Thread rebus_
2009/11/12 Dirk Uys :
> I have a model with a from and to date:
>
> class Event (models.Model):
>     start_date = models.DateField()
>     end_date = models.DateField()
>
> In order to ensure start_date is always before end_date i can think of 3
> options:
>
> 1. Use form validation iow in the clean method of an inherited form
> 2. Use the django.db.models.signals.pre_save signal
> 3. Create a custor field that takes an parameter of the date field wich must
> allways be greater than or less than
>
> What is the easiest way to achieve this?
>
> Regards
> Dirk
>
> --

You can add custom clean methods in your form:

class Event (models.Model):
start_date = models.DateField()
end_date = models.DateField()

   def clean(self):
   start = self.cleaned_data.get('start_date', False)
   end = self.cleaned_data.get('end_date', False)
   if not start or not end:
  raise forms.ValidationError('message')
   if start > end:
  raise forms.ValidationError('start is greater then end')
   return self.cleaned_data

This is just an example code.

Using this approach validation errors will not be associated with and field.
You could write clean_start_date and clean_end_date methods which
would evaluate each field and all validation errors would be
associated with specific field.

To learn more about form validation read [1] or [2]:

[1] http://docs.djangoproject.com/en/dev/ref/forms/validation/
[2] 
http://code.djangoproject.com/browser/django/trunk/docs/ref/forms/validation.txt

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Prevent brute-force password attacks?

2009-11-12 Thread rebus_
How about using some system that after few failed logins gives some
CAPTCHA to solve? I think it's ok way to get rid of some bots.

I think it could be easily done by setting up custom login view.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Model validation

2009-11-12 Thread Dirk Uys
I have a model with a from and to date:

class Event (models.Model):
start_date = models.DateField()
end_date = models.DateField()

In order to ensure start_date is always before end_date i can think of 3
options:

1. Use form validation iow in the clean method of an inherited form
2. Use the django.db.models.signals.pre_save signal
3. Create a custor field that takes an parameter of the date field wich must
allways be greater than or less than

What is the easiest way to achieve this?

Regards
Dirk

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: URLs and masking of private objects

2009-11-12 Thread Mike Ramirez
On Thursday 12 November 2009 02:48:35 Mike Ramirez wrote: 
> urlpatterns = patterns('', url(r'^portfolios/(?P[\w-]+$',
> 'portfolio.views.load_details', name='details'),
> 
Typo fixes:
urlpatterns += patterns('', url(r'^portfolios/(?P[\w-]+)$',  
'portfolio.views.load_details', name='details'), )

-- 
"An open mind has but one disadvantage: it collects dirt."
-- a saying at RPI


signature.asc
Description: This is a digitally signed message part.


Re: Making the case for Django (vs. Drupal)

2009-11-12 Thread bruno desthuilliers


On 12 nov, 01:16, shacker  wrote:
> I've just put up a
> pretty complete draft of a post on this topic, written with decision
> makers (managers, supervisors) in mind. It's still probably somewhat
> technical for that group, but that's the nature of the topic.
>
> http://birdhouse.org/blog/2009/11/11/drupal-or-django/
>
>
> Feedback and further contributions welcome.
>

A couple things that came to mind while reading your draft:

1/ wrt/ performances AND rapid development : I recently had to work on
a not-so-complex (functionaly-wise) Durpal project, and the response
times on my local station - all caches disabled of course - turned the
development process into a sluggish nightmare. Never had this kind of
problems with Django, even for far more complex apps.

2/ wrt/ rapid development again: I started yesterday afternoon (on my
spare time) a simple virtual gallery application for a painter friend
of mine. I had more than half of the application (including templates
etc) working in a couple hours, and most of the still missing features
will be provided by existing pluggable djang apps. It shouldn't take
more than a couple more hours to have the whole thing up and running.
And when I say "a couple hours", I really mean it, litteraly !-)

Else, I just can second most of the developper's comments : from my
experience, it can take more time doing "simple customisations" on
Drupal than you'd need to implement the same features from scratch in
Python.

My 2 cents.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: awkward backward relationships

2009-11-12 Thread Viktor
Since yesterday, I've put together a small testapp to better present
my problem.

I have the following models.py file:
from django.db import models

class AbstractTaskOrProject(models.Model):
  parent = models.ForeignKey('AbstractProject', null=True)

  class Meta:
abstract = True

class AbstractProject(AbstractTaskOrProject):
  pass

class Project(AbstractProject):
  pass

class SubProject(AbstractProject):
  pass

class Task(AbstractTaskOrProject):
  pass

Then I've run ./manage.py shell to present my point. The output is at
http://python.pastebin.com/m52331203

The weirdest thing to me is that

>>> from django.db.models.query_utils import CollectedObjects
>>> a = CollectedObjects()
>>> project._collect_sub_objects(a)

recognizes the subproject

Is it a bug not to be able to access the Subproject instances from a
parent Project?

V

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Template conceptual help

2009-11-12 Thread Maksymus007
I have some problem with templates and separating templates blocks.

There is a list of messages. Some properties are common, some are
application specific.
Properties are just html columns :)

I got following templates
main.html -> basic "frame", which consists of common html, headers, scripts etc.
frame.html - which introduce additional division - tabs and content,
extends main.html

app_specific.html - app specific tab lists - extends frame.html

messages.html - common message list, which contains common properties
and block in the middle to add custom properites, extends
app_specific.html to be part of app, with proper tabs etc.

app_msg.html - additional properties for messages list, extends messages.html.

My problem is - i need different app_specific.html for different
app_msg.html - is there any way I can achieve that without using
variables from view like context['app_specific_frame'] =
'someapp.html' ? I want to keep clear line between view and
controller.
Any way of simply passing some string along extended templates? Or
possibility to somehow make content of app_msg.html block a content of
extended block from messages.html but wiht extending messages.html?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Uploading and using images in a database application

2009-11-12 Thread bruno desthuilliers


On 11 nov, 08:36, derek  wrote:
> Bruno
>
> All the help is much appreciated - its working now,

Great. Good to know this solved your problem :-)

> and I need to
> spend time to understand all the changes.


Most of them are about avoiding error prone repetitions - IOW, making
this whole thing as DRY as possible.  FWIW, I should probably publish
this recipe somewhere - it's the second time I post it here, and
obviously there's a need for it.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: URLs and masking of private objects

2009-11-12 Thread Flávio Amieiro
On Thu, Nov 12, 2009 at 7:51 AM, Steinar Rune Eriksen  wrote:

>
> (r'^portfolio/(\d{2})/$', 'portfolios.views.load_details'),
> /portfolio/3/
>
> In template the URL would be {% url portfolios.views.load_details
> portfolio.pk %}
>
> Let's say the logged in user has created 2 portfolios, given primary
> keys 3 and 5, and has clicked to view details of object with pk 3.
>
> He does not have access to 1,2,4, but would be tempted to look at
> these URLs and would be wondering if others will be able to view them
>
> Are there a way to rewrite/mask the URL, perhaps via Apache, or would
> one not use such URL mechanisms at all for this type of Web solution?]



I don't think that's the best way to protect your content from other users.

My approach would be to make sure the user only has access to the
appropriate content (i.e. his own) by filtering it in the view.

That way even if he does try to access other user's content via direct URL
he would not be able to do so.

Other than that you could use any other attribute from your model to form
the URL, you only need to make sure it is unique.

Security through obscurity is rarely a good option (*never* if by itself). I
think that a well determined user could probably see through any workarounds
to mask a URL if the  request is going to the URL with an ID in it...

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: URLs and masking of private objects

2009-11-12 Thread Daniel Roseman
On Nov 12, 9:51 am, Steinar Rune Eriksen 
wrote:
> I have not used Django in external environments before, just Intranet
> applications.
>
> I am wondering how to mask URLs so that object IDs are not shown?
> Obviously one would create security on the server to check if a user
> has access to view a particular object, but the fact that IDs are
> siaplayed in the URL would make the Web service look hackable to a lot
> of users.
>
> I am thinking of this type of URL
>
> (r'^portfolio/(\d{2})/$', 'portfolios.views.load_details'),
> /portfolio/3/
>
> In template the URL would be {% url portfolios.views.load_details
> portfolio.pk %}
>
> Let's say the logged in user has created 2 portfolios, given primary
> keys 3 and 5, and has clicked to view details of object with pk 3.
>
> He does not have access to 1,2,4, but would be tempted to look at
> these URLs and would be wondering if others will be able to view them
>
> Are there a way to rewrite/mask the URL, perhaps via Apache, or would
> one not use such URL mechanisms at all for this type of Web solution?

How are you hoping that this would work? Obviously you have to have
some way for the URL to identify the particular portfolio, so you need
to pass some kind of unique identifier in the URL. If you don't want
to show a guessable ID, you'll need to store some other kind of
identifier in the model - perhaps a slug you could create from the
username + portfolio name, or maybe a GUID/UUID.
--
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-us...@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=.




Re: URLs and masking of private objects

2009-11-12 Thread bruno desthuilliers
On 12 nov, 10:51, Steinar Rune Eriksen  wrote:
> I have not used Django in external environments before, just Intranet
> applications.
>
> I am wondering how to mask URLs so that object IDs are not shown?
> Obviously one would create security on the server to check if a user
> has access to view a particular object, but the fact that IDs are
> siaplayed in the URL would make the Web service look hackable to a lot
> of users.
>
> I am thinking of this type of URL
>
> (r'^portfolio/(\d{2})/$', 'portfolios.views.load_details'),
> /portfolio/3/
>
> In template the URL would be {% url portfolios.views.load_details
> portfolio.pk %}
>
> Let's say the logged in user has created 2 portfolios, given primary
> keys 3 and 5, and has clicked to view details of object with pk 3.
>
> He does not have access to 1,2,4, but would be tempted to look at
> these URLs and would be wondering if others will be able to view them
>
> Are there a way to rewrite/mask the URL, perhaps via Apache, or would
> one not use such URL mechanisms at all for this type of Web solution?

"Security thru obscurity" is a well-known antipattern. The obvious
answer to your problem is to handle per-object (aka row-level)
permissions in your application.

If the rules are simply "a logged in user can only access it's own
portfolios", then all you have to do is to check (in your views) if
the request.user is the portofolio.owner (assuming you didn't forget
to have this relationship ).

Else you need a real row-level permissions system - which doesn't yet
exists in Django itself so it'll need a bit more work. One solution
might be to use authorithy (http://packages.python.org/django-
authority/). But support for row-level permissions in Django itself is
scheduled for the 1.2 release, and already available as a patch
(http://code.djangoproject.com/ticket/11010). Note that the patch only
provide _support_ for this feature - you'll still have to implement
the row-level permissions by yourself (which, FWIW, is what I'm
working on ATM ).

HTH

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: form with loop over fields?

2009-11-12 Thread David De La Harpe Golden
andreas schmid wrote:

> the values of the form should be stored and re-edited when necessary.
> that would be only a part of the whole thing, i implemented the rest of
> the form through a model and generating the form trough it.
> 

Re the "a model" singular:
Conceptually, you're defining a model or models for your domain, and
autogenerating forms from them via a ModelForm or ModelForms.

Django ORM is quite "thin" out-of-box, a model class maps to a table and
an instance of a model maps to a database row, pretty much.  While you
could have a single database table of thingies with 120 fields for 120
months of data in each row for each thingy, it's mostly plain awkward to
work that way - especially if it's supposed to be some sliding
last-10-year window.  There are peculiar situations where you might do
it as a optimization.  A matter of database design, not django-specific.

You're more likely to use more than one model, perhaps along the lines of:

class Thingy(models.Model):
stuff = models.TextField()

class ThingyRelatedMonthlyDatum(models.Model):
thingy = models.ForeignKey(Thingy)
month_beginning = models.DateField()
datum =  models.IntegerField(null=True)

















> 
> David De La Harpe Golden wrote:
>> andreas schmid wrote:
>>   
>>> hi ,
>>>
>>> i need to create an input form with a input field for every month for
>>> lets say 10 years.
>>> so the form has 10*12 = 120 exact same input fields.
>>>
>>> 
>> Do you mean tabular sort of form?
>>
>>gross  deductible
>> 2009-11-11 [...]  [...]
>> 2009-11-10 [...]  [...]
>> sort of thing?
>>
>>   
>>> is there a way to define the field only once or maybe define a year with
>>> 12 fields and loop over it to avoid having a huge model?
>>>
>>> 
>> There are certainly ways of doing it directly as one django form object
>> (python is quite dynamic), but you could maybe look at the FormSet
>> infrastructure - one form per month in a formset.
>>
>> http://docs.djangoproject.com/en/dev/topics/forms/formsets/
>>
>> An important thing to bear in mind when working with django forms is
>> that 1 django form doesn't have to map to 1 html form.  You can use N
>> django form objects in 1 html form, separating them with a prefix.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>   
> 
> 
> --~--~-~--~~~---~--~~
> 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-us...@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=.




Re: URLs and masking of private objects

2009-11-12 Thread Mike Ramirez
On Thursday 12 November 2009 01:51:26 Steinar Rune Eriksen wrote:
> I have not used Django in external environments before, just Intranet
> applications.
> 
> I am wondering how to mask URLs so that object IDs are not shown?
> Obviously one would create security on the server to check if a user
> has access to view a particular object, but the fact that IDs are
> siaplayed in the URL would make the Web service look hackable to a lot
> of users.
> 
> I am thinking of this type of URL
> 
> (r'^portfolio/(\d{2})/$', 'portfolios.views.load_details'),
> /portfolio/3/
> 
> In template the URL would be {% url portfolios.views.load_details
> portfolio.pk %}
> 
> Let's say the logged in user has created 2 portfolios, given primary
> keys 3 and 5, and has clicked to view details of object with pk 3.
> 
> He does not have access to 1,2,4, but would be tempted to look at
> these URLs and would be wondering if others will be able to view them
> 
> Are there a way to rewrite/mask the URL, perhaps via Apache, or would
> one not use such URL mechanisms at all for this type of Web solution?
> 

I use slugs[1] instead of id's for my urls, most of my models have a 
title/name attribute that I slugify, the title/name attribute should be unique 
also, but this is how I mask things from id's.  

Example:

# assumes namespaces[2] to call this:
# {% url portfolio:details portfolio.slug %}

urlpatterns = patterns('', url(r'^portfolios/(?P[\w-]+$', 
'portfolio.views.load_details', name='details'), 

# In models.py for the base class

from django import models
from django.template.defaultfilters import slugify

class MyBaseModel(models.Model):
title = models.CharField(max_length=50, unique=True)
# don't need to edit in the admin panel
# since it's automagically slugified in the save method
slug = models.SlugField(editable=False)

class Meta:
abstract=True

@models.permalink
def get_absolute_url(self):
return ('portfolio:details', (), {'slug': self.slug })

def save(self, *args, **kwargs):
# might want to do this during pre_save to check if changed
self.slug = slugify(self.title)
super(MyBaseModel, self).save(*args, **kwargs)


urls should look like: /portfolio/my-cool-pictures for the portfolio with the 
title "My Cool Pictures"

[1] http://docs.djangoproject.com/en/dev/ref/models/fields/#slugfield
[2] http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-
defining-url-namespaces

Mike


He hadn't a single redeeming vice.
-- Oscar Wilde


signature.asc
Description: This is a digitally signed message part.


Re: View using 2 models

2009-11-12 Thread bruno desthuilliers
On 12 nov, 07:07, EmileZola  wrote:
> Alright, I'm pretty new to Django and I've got this problem I can't
> quite solve.
>
> I basically have two models, wich I use to put blog articles into
> categories. One is a Category and the other is a Subject. So in my
> categories I might have ('Programming', 'Music', 'Essays') and my
> subjects are listed under those various categories. So under
> Programming I might have ('Python', 'PHP', 'ASM').
>
> Here a stripped down version of my models :
>
> class Category(models.Model):
> name = models.CharField(_('Categorie'), max_length=100)
>
> class Subject(models.Model):
> name = models.CharField(_('Forum'), max_length=100)
> description = models.CharField(_('Description'), max_length=250)
> category = models.ForeignKey(Category)
>
> Now, what I try to do in my view, is to loop through the categories
> and list each subject it contains. Someone can help me ?

Why do you want to do this in the view ??? If it's for rendering
purpose - which I guess is the case - just pass the appropriate
Category queryset to your context, then do the loop in the template,
ie:


# yourapp/views.py

def category_list(request, ...):
   context = dict(categories = Category.objects.all().select_related
())
   return render_to_response(
  "yourapp/category_list.html",
  context,
  context_instance=RequestContext(request)
  )

# yourapp/category_list.html


{% for category in categories %}
  
{{ category.name }}

{% for subject in category.subject_set.all %}
  {{ subject.name }}
{% endfor %}

  
{% endfor %}


HTH - Or did I miss the point ?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Accessing 'bytea' field using django.

2009-11-12 Thread ds99
Thanks all for your comments and suggestions. I will definitely take
them into account.

-ds99

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: View using 2 models

2009-11-12 Thread Dirk Uys
On Thu, Nov 12, 2009 at 8:07 AM, EmileZola  wrote:

> Alright, I'm pretty new to Django and I've got this problem I can't
> quite solve.
>
> I basically have two models, wich I use to put blog articles into
> categories. One is a Category and the other is a Subject. So in my
> categories I might have ('Programming', 'Music', 'Essays') and my
> subjects are listed under those various categories. So under
> Programming I might have ('Python', 'PHP', 'ASM').
>
> Here a stripped down version of my models :
>
> class Category(models.Model):
> name = models.CharField(_('Categorie'), max_length=100)
>
> class Subject(models.Model):
> name = models.CharField(_('Forum'), max_length=100)
> description = models.CharField(_('Description'), max_length=250)
> category = models.ForeignKey(Category)
>
> Now, what I try to do in my view, is to loop through the categories
> and list each subject it contains. Someone can help me ?
>

for category in Category.objects.all():
print category
for subject in category.subject_set.all():
print subject

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




URLs and masking of private objects

2009-11-12 Thread Steinar Rune Eriksen
I have not used Django in external environments before, just Intranet
applications.

I am wondering how to mask URLs so that object IDs are not shown?
Obviously one would create security on the server to check if a user
has access to view a particular object, but the fact that IDs are
siaplayed in the URL would make the Web service look hackable to a lot
of users.

I am thinking of this type of URL

(r'^portfolio/(\d{2})/$', 'portfolios.views.load_details'),
/portfolio/3/

In template the URL would be {% url portfolios.views.load_details
portfolio.pk %}

Let's say the logged in user has created 2 portfolios, given primary
keys 3 and 5, and has clicked to view details of object with pk 3.

He does not have access to 1,2,4, but would be tempted to look at
these URLs and would be wondering if others will be able to view them

Are there a way to rewrite/mask the URL, perhaps via Apache, or would
one not use such URL mechanisms at all for this type of Web solution?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: admin.site.register() - help

2009-11-12 Thread neridaj
Thanks Matt, that did it.

On Nov 11, 11:07 pm, Matt Schinckel  wrote:
> On Nov 12, 4:18 pm, neridaj  wrote:
>
> > since FlatPage is already registered how do I properly register an
> > InlineModelAdmin object?
>
> You can use:
>
> admin.site.unregister(FlatPage)
>
> and then re-register with your FlatPageAdmin class:
>
> admin.site.register(FlatPage, MyFlatPageAdmin)

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Author Django Book-Packt Publishing.

2009-11-12 Thread Kshipra Singh
Hi All,

I represent Packt Publishing, the publishers of computer related
books.

We are planning to publish a new book on Django, titled Django Ajax
and are currently inviting potential authors to write it. We pay a
royalty of 16% and an advance against it.

The ideal candidate will be someone with good knowledge of Django and
Ajax & a passion to share it with others.
He/She should be well conversant in English. Past writing experience
will be an advantage though not mandatory.

If you find it interesting to author this book, please write to
kship...@packtpub.com with a brief about your relevant experience

Thanks
Kshipra Singh
Author Relationship Manager
Packt Publishing
www.PacktPub.com

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




View using 2 models

2009-11-12 Thread EmileZola
Alright, I'm pretty new to Django and I've got this problem I can't
quite solve.

I basically have two models, wich I use to put blog articles into
categories. One is a Category and the other is a Subject. So in my
categories I might have ('Programming', 'Music', 'Essays') and my
subjects are listed under those various categories. So under
Programming I might have ('Python', 'PHP', 'ASM').

Here a stripped down version of my models :

class Category(models.Model):
name = models.CharField(_('Categorie'), max_length=100)

class Subject(models.Model):
name = models.CharField(_('Forum'), max_length=100)
description = models.CharField(_('Description'), max_length=250)
category = models.ForeignKey(Category)

Now, what I try to do in my view, is to loop through the categories
and list each subject it contains. Someone can help me ?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.