Re: How to get child model' name from parent obj in Multi-table inheritance

2008-05-31 Thread David Zhou

On May 30, 2008, at 11:20 AM, jonknee wrote:

> On May 30, 10:38 am, David Zhou <[EMAIL PROTECTED]> wrote:
>> You can use also use hasattr().
>>
>> Something like
>>
>> if hasattr(person_obj, 'man'):
>>  #is man
>> elif hassattr(person_obj, 'woman'):
>>  #is woman
>> else:
>>  #is freakish mutated thing
>>
>
> How would that work exactly? It's a reverse relation, so you need to
> specify what exactly you want (e.g. the data from the Man or Woman
> table). It can't automatically go out and get it.
>
> http://www.djangoproject.com/documentation/model-api/#inheritance-and-reverse-relations

Why wouldn't that work, unless I'm misunderstanding something?

 From the docs:

 >>> p = Place.objects.filter(name="Bob's Cafe")
# If Bob's Cafe is a Restaurant object, this will give the child class:
 >>> p.restaurant

However, if p in the above example was not a Restaurant (it had been  
created directly as a Place object or was the parent of some other  
class), referring to p.restaurant would give an error.

I'm assuming he's already done:

person_obj = get_object_or_404(Person, pk=person_id)

I'm also assuming one will always create person objects through the  
Man or Woman classes.  And even if he didn't, that should still  
trigger the third default else choice.


---
David Zhou
[EMAIL PROTECTED]




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: A for B C as D in templates

2008-05-31 Thread Julien

This is not a standard syntax but the particular syntax for the tag
get_free_comment_count. Check its code in
django.contrib.comments.templatetags.DoCommentCount

In your example, 'blog' is the application name, 'entry' the model
name to which comments are attached, 'object.id' is the id of the
particular object you're retrieving the comments for.

What it does is it retrieves the comments and stores the number of
comments in the variable 'comment_count', which you can then use as
follows:

There are {{ comment_count }} comment{{ comment_count|pluralize }} for
this entry.



On Jun 1, 12:02 pm, Rodrigo Culagovski <[EMAIL PROTECTED]> wrote:
> Looking through documentation for the FreeComment app, I came across
> this template syntax:
>
> {% get_free_comment_count for blog.entry object.id as comment_count %}
>
> Where can I find documentation for use of the "A for B C as D"  syntax
> in Django templates?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the model name

2008-05-31 Thread Eric Abrahamsen

Are you maybe talking about changing the underlying database table name?

http://www.djangoproject.com/documentation/model-api/#table-names



On Jun 1, 2008, at 2:45 AM, Kless wrote:

>
> Is possible to change the model name?
>
> From a class as *class FooBar*
> it's got a model called *foobar*,
> but I would to get a model called 'foo_bar', without change the class
> name to 'Foo_Bar'.
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Silly question on models

2008-05-31 Thread [EMAIL PROTECTED]

I would suggest adding a field for "source", which you can grab from
the RSS feed or submit from the form to keep track of where it came
from, and some sort of status field (submitted/published) to hold them
until someone has reviewed the submissions.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: url parameters go missing

2008-05-31 Thread M.Ganesh

Karen Tracey wrote:
> On Sat, May 31, 2008 at 3:29 AM, M.Ganesh <[EMAIL PROTECTED] 
> > wrote:
>
>
> Karen Tracey wrote:
> > On Fri, May 30, 2008 at 9:48 PM, Karen Tracey
> <[EMAIL PROTECTED] 
> > >> wrote:
> >
> > On Fri, May 30, 2008 at 7:53 PM, M.Ganesh
> <[EMAIL PROTECTED] 
> >  >> wrote:
> >
> >
> > Hi All,
> >
> > I have this url to start a note_l1 addition :
> > '/contacts/note_l1/add/?entity=2'
> >
> > This reaches the server and my code intact. An 'Add; page is
> > displayed.
> > After I fill the form and press the 'Add' button only the
> > '/contacts/note_l1/add/' portion reaches the server. the
> > '?entity=2'  is
> > missing. I want to use this 'entity=2' info to redirect
> to the
> > relevant
> > page. Unable to figure out what is happening. Can somebody
> > kindly have a
> > look.
> >
> > The details are here : http://dpaste.com/hold/53853/
> >
> > Thanks in advance
> >
> >
> > The url used for the form's POST is specified on the 
> action
> > attribute.  What are you specifying for action= in your
> template?
> > Dot goes back to the same page, but I don't believe it carries
> > along query strings.  So if you want your POST to include a
> query
> > string I think you'll need to pass it through from the GET
> > handling part of your view into your template so it can be
> > included as part of the form's action attribute.
> >
> >
> > Oops, also meant to mention probably a more common way of handling
> > this kind of thing is via a hidden field in your form.
> >
> > Karen
> Thanks Karen for your suggestion. But I further played around with the
> above setup and have some intriguing observations.
>
> Instead of adding a 'note_l1' object, I tried adding a 'emailid'
> object.
> The view function worked as expected. The differences   between the
> 'note_l1' and 'emailid' objects, as far as I could see are :
> 1. 'emailid' is a plain model whereas 'note_l1' is inherited from an
> abstract model.
> 2. 'note_l1'  involves genericRelations
>
>
> The really significant difference between your other models and your 
> new emailid model is email id has an 'entity' field.  So when you POST 
> the form to create a new emailid this line of code:
>
> if request.REQUEST.has_key('entity'):
>
> returns True.  But it's pulling 'entity' from the post data, not from 
> the query string.  As you note in your annotation of the runserver 
> output, there is no query string included in the POST.  The entity 
> value you get here will be whatever the user has selected for 'Entity' 
> in the posted form, it is not going to be tied at all to the 'entity' 
> query parameter on the original url.
>  
>
> Yes, it is action = "." indeed in the template
>
>
> So based on experimentation (I haven't bothered to look it up in any 
> standard), I believe this is where you lose the query string.  Form 
> action="." goes back to the url used for the GET, minus any query string.
>
> Karen
>
> The details (Version 2.0) are here : http://dpaste.com/hold/53887/
>
> My Django version 0.97-pre-SVN-7543
>  
> Hope you can spend some more time on this.
>
> Thanks in advance
>  
> Regards Ganesh
>
Thanks Karen, for providing the insight into 'POST' behavior. I'll use 
hidden fields to achieve my purpose.

Incidentally,  I  tried the above code with Apache-mod_python as well. 
The access.log of apache is here : http://dpaste.com/hold/54002/.  There 
POST request also get the url parameters. Still it behaves the same way 
as with runserver.

Thanks for your time once again
Regards Ganesh


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



A for B C as D in templates

2008-05-31 Thread Rodrigo Culagovski

Looking through documentation for the FreeComment app, I came across
this template syntax:

{% get_free_comment_count for blog.entry object.id as comment_count %}

Where can I find documentation for use of the "A for B C as D"  syntax
in Django templates?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: I get an error when using django and postgresql. ProgrammingError: invalid byte sequence for encoding

2008-05-31 Thread Karen Tracey
On Sat, May 31, 2008 at 7:25 PM, Nathan Zorn <[EMAIL PROTECTED]> wrote:

>
> I am using django and postgresql and get an error when I pass in
> unicode to filter.
>
> ProgrammingError: invalid byte sequence for encoding "UTF8":
>
>
> The documentation states that I can pass both in and that django
> detects what encoding the database uses.  Should this be repoted as a
> bug?
>

Not without a lot more specifics.  What, exactly, is the unicode sequence
that is causing the error?  How are you creating it and what Django calls
are you making that result in the database returning this 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



I get an error when using django and postgresql. ProgrammingError: invalid byte sequence for encoding

2008-05-31 Thread Nathan Zorn

I am using django and postgresql and get an error when I pass in
unicode to filter.

ProgrammingError: invalid byte sequence for encoding "UTF8":


The documentation states that I can pass both in and that django
detects what encoding the database uses.  Should this be repoted as a
bug?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need an example of how to use TagField in a template

2008-05-31 Thread M Godshall

Alex, thanks for your response.  Let me give you an example of what I
started to do, and I'd appreciate your feedback to see if this would
actually work (or if it's just a bad way of doing it).

Let's say I wanted to let users submit tags for books on a site.  A
simple model might look like this:

class Book(models.Model):
   title = models.CharField()
   slug = models.SlugField(prepopulate_from=('title'))
   author = models.ForeignKey(Author)
   tag = TagField()
   ...

In the django-tagging documentation, it mentions that using newforms'
"ModelForm" on a TagField will automatically create a TagField for a
form.  However, I only want to create a field for the tags, not title
or author.  Currently, I'm trying to do something like this:

class BookTagForm(ModelForm):
   class Meta:
  model = Book
  fields = ('tag')

I'm using the following url conf to generate the book details page:
(r'^(?P\w+)/(?P[-\w]+)/$', views.book_details).  My goal
is for each book details page will have its own form for users to
submit tags (using BookTagForm) for that particular book.

In my view for the page, I create the form using tagform =
BookTagForm(), and I'm able to generate the TagField by calling
{{ tagform }} in my template.  It looks like this:


{{ tagform }}



At this point, a TagField is displayed on the page, but I'm confused
how to process tags so that they save for that particular book (the
one being displayed by book_details).  I guess I'm asking two
questions:

1. Am I heading in the right direction with this approach, or should I
toss any parts of it?
2. Can you be more specific on the view I need to write in order to
process user submitted tags for the book whose page they're visiting?
I'm still learning newforms, and would appreciate any additional help
you can give.

Thank you!


On May 31, 11:18 am, "Alex Ezell" <[EMAIL PROTECTED]> wrote:
> On Sat, May 31, 2008 at 12:46 PM, M Godshall <[EMAIL PROTECTED]> wrote:
>
> > I was hoping someone could show me an example of how to use django-
> > tagging's TagField to submit tags from a template.  I have the
> > TagField setup in my model that I can edit in the admin, but I am
> > having trouble figuring out how to submit tags from a template.  Could
> > someone please point me in the right direction?
>
> I use a form from newforms to do it. Something like this (obviously,
> this is just partial code):
>
> forms.py:
> from django import newforms as forms
> from tagging.forms import TagField
>
> class MyForm(forms.Form):
>     title = forms.CharField(max_length=150)
>     tags = TagField()
>
> template.html:
> Tags:
> {{ form.tags }}
>
> views.py:
> if request.method == 'POST':
>         form = MyForm(request.POST)
>         if form.is_valid():
>             post = form.save(id=id, commit=False)
>             if id is None:
>                 post.owner = request.user
>             post.save() # this will save the tags also
>
> I'm assuming you know how to create a form in your view and pass it to
> the template. When you save this form in your view, the the TagField
> is smart enough to know how to save the tags and associate them with
> the model object you've just saved. Your method of saving the form in
> the view will vary greatly from the pseudocode I've posted.
>
> That said, there are more direct methods of saving tags available via
> the API of django-tagging. This seems to me to be the easiest
> depending on your needs.
>
> /alex
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to validate form field to be numeric

2008-05-31 Thread Karen Tracey
On Sat, May 31, 2008 at 3:51 PM, meppum <[EMAIL PROTECTED]> wrote:

> I want to make sure that the value is a positive integer, but there
> doesn't seem to be a widget for that.
>

Take a close look at the docs for IntegerField and I think you'll see you
can use it for this purpose:

http://www.djangoproject.com/documentation/newforms/#integerfield

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



Re: django error about syncdb

2008-05-31 Thread Karen Tracey
On Sat, May 31, 2008 at 2:07 AM, tony yu <[EMAIL PROTECTED]> wrote:

>
> version info:
> django svn version, freebsd 7.0, python 2.5.2
> settings.py:
> INSTALLED_APPS = (
>'django.contrib.auth',
>'django.contrib.contenttypes',
>'django.contrib.sessions',
>'django.contrib.sites',
>'django.contrib.admin',
>'mysite.polls',
> )
>
> the os stdout:
> [EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
> Creating table auth_message
> Creating table auth_group
> Creating table auth_user
> Creating table auth_permission
> Creating table django_content_type
> Creating table django_session
> Creating table django_site
> Creating table django_admin_log
> Creating table polls_poll
> Creating table polls_choice
>
> You just installed Django's auth system, which means you don't have
> any superusers defined.
> Would you like to create one now? (yes/no): yes
> Username (Leave blank to use 'root'): root
> E-mail address: [EMAIL PROTECTED]
> Password:
> Password (again):
> Superuser created successfully.
> Installing index for auth.Message model
> Installing index for auth.Permission model
> Installing index for admin.LogEntry model
> Installing index for polls.Choice model
> Error: One or more models did not validate:
> auth.group: "admin.list_display" refers to '__ipow__', which isn't an
> attribute, method or property.
>

That's bizarre.  Model validation succeeds once, the tables are added and
indices are created, then when syncdb goes to try and load fixtures it runs
model validation again and this time it dies.

I assume you have not changed anything in the django/contrib/auth/models.py
file?

Did this happen the very first time you ran syncdb or not until you added
something (django.contrib.admin, mysite.polls)?  If you try removing
mysite.polls from INSTALLED_APPS does the problem go away?  If it does, then
the problem is somewhere in what you've done with mysite/polls, though I
have no idea what.

Karen












>
> Karen, thank you.
>
> On 5月30日, 下午9时22分, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> > On Fri, May 30, 2008 at 4:55 AM, tony yu <[EMAIL PROTECTED]> wrote:
> >
> > > when I use syncdb, get the error:
> >
> > > [EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
> > > Error: One or more models did not validate:
> > > auth.group: "admin.list_display" refers to '__ipow__', which isn't an
> > >
> attribute, method or property.
> >
> > > pls help me, thanks!
> >
> > What version of Django?
> >
> > What is the value for INSTALLED_APPS in your settings.py?
> >
> > If your INSTALLED_APPS includes 'django.contrib.auth', what happens when
> you
> > remove it and try 'python manage.py syncdb' again?
> >
> > 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the model name

2008-05-31 Thread Kless

No, it wasn't about that, but thanks anyway.

On 31 mayo, 21:08, "Joseph Heck" <[EMAIL PROTECTED]> wrote:
> If you're talking about changing the display name in the
> administrative interface, there is the option of setting "verbose
> name" - seehttp://www.djangoproject.com/documentation/model-api/#table-names
> for more information. You can also change the database table name
> associated with the model object if you feel you must. More details
> are in that same documentation page.
>
> -joe
>
> On Sat, May 31, 2008 at 11:45 AM, Kless <[EMAIL PROTECTED]> wrote:
> > Is possible to change the model name?
>
> > From a class as *class FooBar*
> > it's got a model called *foobar*,
> > but I would to get a model called 'foo_bar', without change the class
> > name to 'Foo_Bar'.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Silly question on models

2008-05-31 Thread Pavel Rebrov

Hello everyone!

Sorry for another stupid question, but there it is. I'm building a
news app for a website for a self-teaching and figured out I don't
understand some basic thing. I want news to publish news from
different sources:

1. Add 'em manually all by myself (that's no problem)
2. Allow registered users suggest news to publish (that I also
understand)
3. Allow unregistered site visitors suggest news for publishing (via
form)
4. Republish some posts from RSS feeds while keeping credentials
5. Receive, parse and publish emails.

The model for the news entry itself is pretty straight forward:

class Entry(models.Model):
author = models.ForeignKey(User)
title = models.CharField(max_length=250)
slug = models.SlugField(prepopulate_from=('title',),
unique_for_date=('pub_date'), help_text=u'URL for the entry')
pub_date = models.DateTimeField(u'Date posted',
default=datetime.datetime.today)

body = models.TextField()

categories = models.ManyToManyField(Category)
tags = TagField()

I'm having problems with defining how do I treat relationship between
an Entry and non-authenticated sources (data from a form, rss, email)?
Any suggestions on which way to dig?

Also, any suggestions on what would a better way to manage a queue of
news -- keeping the queue in the Entry model and handling the queuing
via Entry Status or having a separate model for incoming data and re-
inserting news into the Entry model for publishing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



images in templates?

2008-05-31 Thread lindec

So this might be a stupid question, but how exactly does one add an
image to an HTML template in django? I can't seem to figure out where
django thinks my images live. I just want to do, for example,  and cannot get it to display. I've tried altering my
MEDIA_ROOT, putting the image in the same directory as my templates,
putting it in the root directory of my project, in the application
directory, pretty much anywhere you can think of. What am I doing
wrong? Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and i18n

2008-05-31 Thread yml

hello,
I have been using this recipe for some times :
http://yml-blog.blogspot.com/search/label/Internationalisation
It seems to exactly answer your requirements.
I hope that helps.
--yml

On May 30, 6:09 pm, Taevin <[EMAIL PROTECTED]> wrote:
> I've been working with translation in Django and it mostly works but
> I'm wondering if there is a 'cleaner' way of doing things.  That is,
> here is what I seem to have to do to get a page translated into the
> correct language:
>
> URLs are of the form $domain/$language_code/$page 
> (e.g.www.example.com/en/index
> orwww.example.com/fr/index).
>
> 1. Look for a language code in the URL.
> 2. Check the user's session for an existing django_language setting.
> 3. Compare the two (and include edge cases for None with either).
> 3.a. If equal, language is the same, just display the page.
> 3.b. If not equal, set the django_language setting to the language
> code from the URL and then redirect the page to the same URL (this is
> the part that I'm wanting to fix).
>
> In other words, is there a way to immediately set the translation
> language for the output without a page refresh?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Display only some tables

2008-05-31 Thread Kless

1) I want to display any tables to whatever person -public--, but I
want not to display tables of both Auth and Sites models
2) And that only can be added more data only by registered users.

On 31 mayo, 21:04, "Joseph Heck" <[EMAIL PROTECTED]> wrote:
> Hey Kless,
>
> I think you need to be a bit clearer on your question. What are you
> trying to accomplish?
>
> On Sat, May 31, 2008 at 11:47 AM, Kless <[EMAIL PROTECTED]> wrote:
>
> > How to show only any tables to any users -as to the visitors-?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the model name

2008-05-31 Thread Joseph Heck

If you're talking about changing the display name in the
administrative interface, there is the option of setting "verbose
name" - see http://www.djangoproject.com/documentation/model-api/#table-names
for more information. You can also change the database table name
associated with the model object if you feel you must. More details
are in that same documentation page.

-joe

On Sat, May 31, 2008 at 11:45 AM, Kless <[EMAIL PROTECTED]> wrote:
> Is possible to change the model name?
>
> From a class as *class FooBar*
> it's got a model called *foobar*,
> but I would to get a model called 'foo_bar', without change the class
> name to 'Foo_Bar'.
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Display only some tables

2008-05-31 Thread Joseph Heck

Hey Kless,

I think you need to be a bit clearer on your question. What are you
trying to accomplish?

On Sat, May 31, 2008 at 11:47 AM, Kless <[EMAIL PROTECTED]> wrote:
>
> How to show only any tables to any users -as to the visitors-?
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Legacy database, many-to-many field, custom column name and generic foreign key

2008-05-31 Thread MiloZ

Hi,

Here's the problem:

class AssociationClass(models.Model):
fk_model1 = models.IntegerField()
fk_model2 = models.IntegerField()
model2_type = models.IntegerField()

after an inspectdb, I would like to tell django that this is an
association class, with a generic foreign key.

What is the best solution ?

I found this link, it maybe gives a beginning of a solution:
http://undefined.org.ua/blog/2008/02/29/manytomanywithcustomfield/?lang=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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Display only some tables

2008-05-31 Thread Kless

How to show only any tables to any users -as to the visitors-?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Change the model name

2008-05-31 Thread Kless

Is possible to change the model name?

>From a class as *class FooBar*
it's got a model called *foobar*,
but I would to get a model called 'foo_bar', without change the class
name to 'Foo_Bar'.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to get child model' name from parent obj in Multi-table inheritance

2008-05-31 Thread jonknee

On May 30, 11:20 pm, "David.D" <[EMAIL PROTECTED]> wrote:
> If there are lots of child model, use hasattr() or capture exception
> will not be good?
> "add a type field to Person() and overide the save fields on Man and
> Woman to set the type field correctly. " will be better?

hasattr() doesn't work, so you'll need to capture exceptions or create
a new column to track the type. Note that  trying and getting an
exception does take a DB query, so adding a column will be more
efficient.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need an example of how to use TagField in a template

2008-05-31 Thread Alex Ezell

On Sat, May 31, 2008 at 12:46 PM, M Godshall <[EMAIL PROTECTED]> wrote:
>
> I was hoping someone could show me an example of how to use django-
> tagging's TagField to submit tags from a template.  I have the
> TagField setup in my model that I can edit in the admin, but I am
> having trouble figuring out how to submit tags from a template.  Could
> someone please point me in the right direction?

I use a form from newforms to do it. Something like this (obviously,
this is just partial code):

forms.py:
from django import newforms as forms
from tagging.forms import TagField

class MyForm(forms.Form):
title = forms.CharField(max_length=150)
tags = TagField()

template.html:
Tags:
{{ form.tags }}

views.py:
if request.method == 'POST':
form = MyForm(request.POST)
if form.is_valid():
post = form.save(id=id, commit=False)
if id is None:
post.owner = request.user
post.save() # this will save the tags also

I'm assuming you know how to create a form in your view and pass it to
the template. When you save this form in your view, the the TagField
is smart enough to know how to save the tags and associate them with
the model object you've just saved. Your method of saving the form in
the view will vary greatly from the pseudocode I've posted.

That said, there are more direct methods of saving tags available via
the API of django-tagging. This seems to me to be the easiest
depending on your needs.

/alex

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Need an example of how to use TagField in a template

2008-05-31 Thread M Godshall

I was hoping someone could show me an example of how to use django-
tagging's TagField to submit tags from a template.  I have the
TagField setup in my model that I can edit in the admin, but I am
having trouble figuring out how to submit tags from a template.  Could
someone please point me in the right direction?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



escaping of (double) quotes in html-attributes in widgets

2008-05-31 Thread thomas

hi,
i want to code a widget. therefore i need to provide a callback for
the "onclick" event. one of those arguments is a string and thus
between double-quotes. in the html-document the string is no more
between doublequotes but surrounded by "", which of course does
not work. what can i do against that?

cheers and thanx,
thomas
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: url parameters go missing

2008-05-31 Thread Karen Tracey
On Sat, May 31, 2008 at 3:29 AM, M.Ganesh <[EMAIL PROTECTED]> wrote:

>
> Karen Tracey wrote:
> > On Fri, May 30, 2008 at 9:48 PM, Karen Tracey <[EMAIL PROTECTED]
> > > wrote:
> >
> > On Fri, May 30, 2008 at 7:53 PM, M.Ganesh <[EMAIL PROTECTED]
> > > wrote:
> >
> >
> > Hi All,
> >
> > I have this url to start a note_l1 addition :
> > '/contacts/note_l1/add/?entity=2'
> >
> > This reaches the server and my code intact. An 'Add; page is
> > displayed.
> > After I fill the form and press the 'Add' button only the
> > '/contacts/note_l1/add/' portion reaches the server. the
> > '?entity=2'  is
> > missing. I want to use this 'entity=2' info to redirect to the
> > relevant
> > page. Unable to figure out what is happening. Can somebody
> > kindly have a
> > look.
> >
> > The details are here : http://dpaste.com/hold/53853/
> >
> > Thanks in advance
> >
> >
> > The url used for the form's POST is specified on the  action
> > attribute.  What are you specifying for action= in your template?
> > Dot goes back to the same page, but I don't believe it carries
> > along query strings.  So if you want your POST to include a query
> > string I think you'll need to pass it through from the GET
> > handling part of your view into your template so it can be
> > included as part of the form's action attribute.
> >
> >
> > Oops, also meant to mention probably a more common way of handling
> > this kind of thing is via a hidden field in your form.
> >
> > Karen
> Thanks Karen for your suggestion. But I further played around with the
> above setup and have some intriguing observations.
>
> Instead of adding a 'note_l1' object, I tried adding a 'emailid' object.
> The view function worked as expected. The differences   between the
> 'note_l1' and 'emailid' objects, as far as I could see are :
> 1. 'emailid' is a plain model whereas 'note_l1' is inherited from an
> abstract model.
> 2. 'note_l1'  involves genericRelations
>

The really significant difference between your other models and your new
emailid model is email id has an 'entity' field.  So when you POST the form
to create a new emailid this line of code:

if request.REQUEST.has_key('entity'):

returns True.  But it's pulling 'entity' from the post data, not from the
query string.  As you note in your annotation of the runserver output, there
is no query string included in the POST.  The entity value you get here will
be whatever the user has selected for 'Entity' in the posted form, it is not
going to be tied at all to the 'entity' query parameter on the original url.


> Yes, it is action = "." indeed in the template
>

So based on experimentation (I haven't bothered to look it up in any
standard), I believe this is where you lose the query string.  Form
action="." goes back to the url used for the GET, minus any query string.

Karen

The details (Version 2.0) are here : http://dpaste.com/hold/53887/
>
My Django version 0.97-pre-SVN-7543
>
> Hope you can spend some more time on this.
>
> Thanks in advance
>
> Regards Ganesh
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use variables inside an 'include' tag (and/or: how to set a variable in a template)

2008-05-31 Thread @@
On 5/31/08, Alex Morega <[EMAIL PROTECTED]> wrote:
>
>
>
> On May 31, 2008, at 00:36 , Berco Beute wrote:
>
> >
> > Unfortunately that doesn't work. This works:
> >
> > {{ include dir|concat:"/tag.html" }}
> >
> > But not this:
> >
> > {% include dir|concat:"/tag.html" %}
> >
> > Thanks, but I'm still searching for a solution...
>
> Create your own tag - not an inclusion tag, but a simpletag. Something
> like this:
>
> from django.template.loader import render_to_string
> from django import template
> register = template.Library()
>
> @register.simple_tag
> def my_include(directory, filename):
> return render_to_string(directory + filename)



this will works for the include tag, but what about the extends tag.
it would be nice if it's possible to use variable in the {%%}

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Just getting started

2008-05-31 Thread Russell Keith-Magee

On Thu, May 29, 2008 at 10:14 PM, jfinke <[EMAIL PROTECTED]> wrote:
>
> The problem then becomes is there any easy to sync the notebook
> information back with HQ when the notebooks come home or VPN in or
> whatever?  Do I need to write a program to export it out and then
> import it back in?  Or are there already existing features that handle
> something like disconnected clients?

To the best of my knowledge, there isn't an 'out of the box' solution
for this. However, it can be done - I've been involved in the
development of an implementation of a system that is almost identical
to the one you describe.

In the implementation I was working on, the architecture went
something like this:

 * There was a single set of models; the main server ran Postgres, and
kept the canonical copy. The clients (tablet PCs and handhelds) ran
SQLite versions in their own local server.

 * On first connection, the client would poll an 'export' URL on the
server that would pull down, in XML format, a dump of the relevant
table content from the server which would be loaded into the client's
local SQlite database. The server keeps track of which rows of data
(specifically, which primary keys - more on this later) have been sent
to the client.

 * The client would then operate as a normal Django application, using
the local SQLite database. Users use a web application running against
a local server; there is no need for a connection between the main
server and the client machine.

 * When the client reconnected to the network, it would POST a
serialized version of the local data back to the server via an
'import' URL.

 * The real magic came on the server side. Since there can be multiple
clients connecting to the server, each client could be producing
database entries with conflicting primary keys. As a result, the
server can't just accept the POSTed data as-is - it needs to maintain
an internal accounting table that correlates the primary key on the
client (as provided in the data upload) with the primary key that
exists locally on the server. If a new record is found in the POSTed
data, a new record is created on the server, and the accounting table
stores a record that correlates the server's canonical primary key
with the primary key received from the client.

Essentially, the server maintains a complete picture of all data from
all clients, plus a picture of the primary keys that are available on
each individual client. Whenever the server sends data is sent to the
client, the primary keys are normalized to match the expectations of
the client, and whenever data is received from the client, the primary
keys are normalized  back into the canonical server representation.

Based on my experiences, I suspect that it is something that could be
turned into a generic tool/utility which would make a useful
contribution to the community. Unfortunately, the implementation that
I worked on probably won't ever see the outside world as a generic
tool (due to a combination of factors, including the customer
involved, and the fact that I no longer work at the company that
developed the product).

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: url parameters go missing

2008-05-31 Thread M.Ganesh

Karen Tracey wrote:
> On Fri, May 30, 2008 at 9:48 PM, Karen Tracey <[EMAIL PROTECTED] 
> > wrote:
>
> On Fri, May 30, 2008 at 7:53 PM, M.Ganesh <[EMAIL PROTECTED]
> > wrote:
>
>
> Hi All,
>
> I have this url to start a note_l1 addition :
> '/contacts/note_l1/add/?entity=2'
>
> This reaches the server and my code intact. An 'Add; page is
> displayed.
> After I fill the form and press the 'Add' button only the
> '/contacts/note_l1/add/' portion reaches the server. the
> '?entity=2'  is
> missing. I want to use this 'entity=2' info to redirect to the
> relevant
> page. Unable to figure out what is happening. Can somebody
> kindly have a
> look.
>
> The details are here : http://dpaste.com/hold/53853/
>
> Thanks in advance
>
>
> The url used for the form's POST is specified on the  action
> attribute.  What are you specifying for action= in your template? 
> Dot goes back to the same page, but I don't believe it carries
> along query strings.  So if you want your POST to include a query
> string I think you'll need to pass it through from the GET
> handling part of your view into your template so it can be
> included as part of the form's action attribute.
>
>
> Oops, also meant to mention probably a more common way of handling 
> this kind of thing is via a hidden field in your form.
>
> Karen
Thanks Karen for your suggestion. But I further played around with the 
above setup and have some intriguing observations.

Instead of adding a 'note_l1' object, I tried adding a 'emailid' object. 
The view function worked as expected. The differences   between the 
'note_l1' and 'emailid' objects, as far as I could see are :
1. 'emailid' is a plain model whereas 'note_l1' is inherited from an 
abstract model.
2. 'note_l1'  involves genericRelations

Yes, it is action = "." indeed in the template

The details (Version 2.0) are here : http://dpaste.com/hold/53887/

My Django version 0.97-pre-SVN-7543

Hope you can spend some more time on this.

Thanks in advance

Regards Ganesh


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django error about syncdb

2008-05-31 Thread tony yu

version info:
django svn version, freebsd 7.0, python 2.5.2
settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'mysite.polls',
)

the os stdout:
[EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table polls_poll
Creating table polls_choice

You just installed Django's auth system, which means you don't have
any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'root'): root
E-mail address: [EMAIL PROTECTED]
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Message model
Installing index for auth.Permission model
Installing index for admin.LogEntry model
Installing index for polls.Choice model
Error: One or more models did not validate:
auth.group: "admin.list_display" refers to '__ipow__', which isn't an
attribute, method or property.

Karen, thank you.

On 5月30日, 下午9时22分, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, May 30, 2008 at 4:55 AM, tony yu <[EMAIL PROTECTED]> wrote:
>
> > when I use syncdb, get the error:
>
> > [EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
> > Error: One or more models did not validate:
> > auth.group: "admin.list_display" refers to '__ipow__', which isn't an
> >
attribute, method or property.
>
> > pls help me, thanks!
>
> What version of Django?
>
> What is the value for INSTALLED_APPS in your settings.py?
>
> If your INSTALLED_APPS includes 'django.contrib.auth', what happens when you
> remove it and try 'python manage.py syncdb' again?
>
> 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---