assign dynamic value to form field in django admin

2009-09-25 Thread Joru

Hi

I need to assign one form field dynamically inside django admin when
user change value in select box

class One(models.Model):
name = models.CharField(max_length=200)
code =  models.CharField(max_length=100)

class Two(models.Model):
   two_name = models.CharField(max_length=200)
   oner = models.ForeignKey(One)
   oner_code = models.CharField(max_length=100)

Is it possible if suppose when user add "Two" record, then he change
value in "oner" dropdown and "oner_code" can dynamically change it
value according to what "oner" that being selected?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



name error not defined in models

2009-09-01 Thread Joru

Hi

I got name error in my models when using models.ManyToManyField
Here are my models

class Ank(models.Model):
route = models.ManyToManyField(Dek)
intercity = models.BooleanField()

class Dek(models.Model):
ank = models.ManyToManyField(Ank)

How come I got "NameError: name 'Dek' is not defined" when running
runserver



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



django queryset based on when data created

2009-08-05 Thread Joru

Everytime I edit some data, the data order in queryset changed into
the newest edited
Is it posible to get queryset that ordered based when the data created
without having to add creation date for sorting purpose
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to make field in admin edit view sortable

2009-07-04 Thread Joru

Thanks Karen this work perfectly

On Jul 3, 10:05 pm, Karen Tracey  wrote:
> On Thu, Jul 2, 2009 at 11:52 PM, Joru  wrote:
>
> > is this posible?
>
> Maybe.
>
>
>
> > anyone have solution for this?
>
> Searching for 'sort' on this page:
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/
>
> brings you to a description of the admin_order_field attribute of things in
> list_display that are not database fields.  So,
>
>
>
> > On Jul 2, 4:54 pm, Joru  wrote:
> > > I have following class
>
> > > class ProfileAdmin(UserAdmin):
> > >     list_display = ('username', 'email', 'first_name', 'last_name',
> > > 'is_staff', 'last_login', 'date_joined', 'city')
> > >     def city(self,val):
> > >         return str(val.profile.city)
>
> adding:
>
>         city.admin_order_filed = 'profile__city'
>
> may work, assuming the underlying support for admin_order_filed supports the
> double-underscore reference to a related model's field.  Haven't tried it to
> verify though.
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to make field in admin edit view sortable

2009-07-02 Thread Joru

is this posible?
anyone have solution for this?

On Jul 2, 4:54 pm, Joru  wrote:
> I have following class
>
> class ProfileAdmin(UserAdmin):
>     list_display = ('username', 'email', 'first_name', 'last_name',
> 'is_staff', 'last_login', 'date_joined', 'city')
>     def city
> (self,val):
>         return str(val.profile.city)
>
> I need city to be sortable
> How can I do that?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



how to make field in admin edit view sortable

2009-07-02 Thread Joru

I have following class

class ProfileAdmin(UserAdmin):
list_display = ('username', 'email', 'first_name', 'last_name',
'is_staff', 'last_login', 'date_joined', 'city')
def city
(self,val):
return str(val.profile.city)

I need city to be sortable
How can I do that?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



add other field for django admin user

2009-06-29 Thread Joru

Hi,

Suppose I have UserPref with attribute phone and detail
Is it possible to add UserPref.phone and UserPref.detil in edit form
in django user admin?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: regex problem in django

2009-06-29 Thread Joru

Still doesn't work even I remove wrap function :(

On Jun 29, 7:35 pm, James Gregory  wrote:
> On Jun 29, 1:05 pm, Joru  wrote:
>
> > I'm sorry for my typo
> > the string var suppose to be like this
> > str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n
> > So every match string "wr:" should had "+" in front of it line
> > the one that confuse me is that my function work in django/python
> > shell, but thisregexdoesn't work well if i called it from views.py
> > of my django app
> > So the problem that I faced is that, how come when using django/python
> > shell. myregexwork but not if I put in on my views.py
> > Any hint?
>
> I may be wrong, but I suspect there is a difference between the input
> string/code you are using in the shell, and the input string/code you
> are using in the view. What happens if make a new empty Python script
> and cut and paste in your code (removing the wrap function from
> Django). Does it work then?
>
> James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: regex problem in django

2009-06-29 Thread Joru

I'm sorry for my typo
the string var suppose to be like this
str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n
So every match string "wr:" should had "+" in front of it line
the one that confuse me is that my function work in django/python
shell, but this regex doesn't work well if i called it from views.py
of my django app
So the problem that I faced is that, how come when using django/python
shell. my regex work but not if I put in on my views.py
Any hint?

On Jun 29, 5:49 pm, James Gregory  wrote:
> On Jun 29, 11:19 am, Joru  wrote:
>
> > ah, I just want to match in the end of line only
> > so change the rule "wr$" would get what I want?
>
> > > Square brackets are for character groups, not literal strings. "wr:"
> > > is just a string so it should be "wr:", not "[wr:]". Also, you want to
> > > match the beginning of the line, not the end, so it should be
> > > something like "^wr:", not "wr$". Unless I've missed something.
>
> When you split your test string on newlines you get:
>
> "wr:"
> " one bunny"
> " two bunny"
> " wr: three bunny"
>
> In the first line "wr:" is at both the beginning and end of the
> string, as it is the whole string. The next two lines do not feature
> "wr:" at all. On the last line "wr:" is at neither the beginning nor
> the end of the string - it has " " in front, and " three bunny"
> afterwards. Depending on what you want to do you might want to call
> strip() on each line, in which case the 4th line  would become "wr:
> three bunny", making wr: the beginning of the line. It depends what
> you want to do, and anyway I can't write your program for you.
>
> Essentially, you just need to spend some time reading a bit more about
> regular expressions:http://docs.python.org/library/re.html
>
> James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: regex problem in django

2009-06-29 Thread Joru

ah, I just want to match in the end of line only
so change the rule "wr$" would get what I want?

On Jun 29, 4:56 pm, James Gregory  wrote:
> On Jun 29, 10:49 am, Joru  wrote:
>
>
>
> > I mean None not null
> > When I print rgx always None, that mean theregexeval never match
> > The expected output result would be
>
> > +wr:> one bunny
> > > two bunny
>
> > + wr: three bunny
>
> > Because everytime foundregexrules r'[wr:]$' then should add + in
> > beginning of line
>
> > On Jun 29, 4:31 pm, James Gregory  wrote:
>
> > > On Jun 29, 10:05 am, Joru  wrote:
>
> > > > I still can't solve this
> > > > Anyone had answer on this?
>
> > > > On Jun 26, 7:39 pm, Joru  wrote:
>
> > > > > Hi,
>
> > > > > I experience some weirdness regarding usingregexwith django
> > > > > I have following function in utils.py
>
> > > > > from django.utils.text import wrap
> > > > > import re
>
> > > > > str = "wr: \n one bunny \n two bunny \n wr: three bunny \n
> > > > > def do_regex(text):
> > > > >     lines = wrap(text, 55).split('\n')
> > > > >     for i, line in enumerate(lines):
> > > > >         cmp = re.compile(r'[wr:]$')
> > > > >         rgx = cmp.search(line)
> > > > >         if rgx:
> > > > >             line = "+%s" % line
> > > > >             lines[i] = line
> > > > >         else :
> > > > >             lines[i] = ">%s" % line
> > > > >     return '\n'.join(lines)
> > > > > do_regex(str)
>
> > > > > when calling do_regex() from views.py, I always get rgx null while
> > > > > when I use django shell rgx will have value when match toregexthat I
> > > > > declare in cmp var
> > > > > How to fix myregexso it can work inside views.py?
>
> > > I copied and pasted your code (with an added speech mark to close str)
> > > into a controller function, and it works for me:
>
> > > Django version 1.1 beta 1, using settings 'pilchard.settings'
> > > Development server is running athttp://127.0.0.1:8000/
> > > Quit the server with CTRL-BREAK.>wr:
> > > > one bunny
> > > > two bunny
> > > > wr: three bunny
>
> > > [29/Jun/2009 10:29:45] "GET / HTTP/1.1" 200 2285
>
> > > What do you mean by "get rgx null"? What exactly is null? Where?
>
> > > James
>
> Square brackets are for character groups, not literal strings. "wr:"
> is just a string so it should be "wr:", not "[wr:]". Also, you want to
> match the beginning of the line, not the end, so it should be
> something like "^wr:", not "wr$". Unless I've missed something.
>
> James
> James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: regex problem in django

2009-06-29 Thread Joru

I mean None not null
When I print rgx always None, that mean the regex eval never match
The expected output result would be

+wr:
> one bunny
> two bunny
+ wr: three bunny

Because everytime found regex rules r'[wr:]$' then should add + in
beginning of line

On Jun 29, 4:31 pm, James Gregory  wrote:
> On Jun 29, 10:05 am, Joru  wrote:
>
>
>
> > I still can't solve this
> > Anyone had answer on this?
>
> > On Jun 26, 7:39 pm, Joru  wrote:
>
> > > Hi,
>
> > > I experience some weirdness regarding usingregexwith django
> > > I have following function in utils.py
>
> > > from django.utils.text import wrap
> > > import re
>
> > > str = "wr: \n one bunny \n two bunny \n wr: three bunny \n
> > > def do_regex(text):
> > >     lines = wrap(text, 55).split('\n')
> > >     for i, line in enumerate(lines):
> > >         cmp = re.compile(r'[wr:]$')
> > >         rgx = cmp.search(line)
> > >         if rgx:
> > >             line = "+%s" % line
> > >             lines[i] = line
> > >         else :
> > >             lines[i] = ">%s" % line
> > >     return '\n'.join(lines)
> > > do_regex(str)
>
> > > when calling do_regex() from views.py, I always get rgx null while
> > > when I use django shell rgx will have value when match toregexthat I
> > > declare in cmp var
> > > How to fix myregexso it can work inside views.py?
>
> I copied and pasted your code (with an added speech mark to close str)
> into a controller function, and it works for me:
>
> Django version 1.1 beta 1, using settings 'pilchard.settings'
> Development server is running athttp://127.0.0.1:8000/
> Quit the server with CTRL-BREAK.>wr:
> > one bunny
> > two bunny
> > wr: three bunny
>
> [29/Jun/2009 10:29:45] "GET / HTTP/1.1" 200 2285
>
> What do you mean by "get rgx null"? What exactly is null? Where?
>
> James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: regex problem in django

2009-06-29 Thread Joru

I still can't solve this
Anyone had answer on this?

On Jun 26, 7:39 pm, Joru  wrote:
> Hi,
>
> I experience some weirdness regarding usingregexwith django
> I have following function in utils.py
>
> from django.utils.text import wrap
> import re
>
> str = "wr: \n one bunny \n two bunny \n wr: three bunny \n
> def do_regex(text):
>     lines = wrap(text, 55).split('\n')
>     for i, line in enumerate(lines):
>         cmp = re.compile(r'[wr:]$')
>         rgx = cmp.search(line)
>         if rgx:
>             line = "+%s" % line
>             lines[i] = line
>         else :
>             lines[i] = ">%s" % line
>     return '\n'.join(lines)
> do_regex(str)
>
> when calling do_regex() from views.py, I always get rgx null while
> when I use django shell rgx will have value when match toregexthat I
> declare in cmp var
> How to fix myregexso it can work inside views.py?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



regex problem in django

2009-06-26 Thread Joru

Hi,

I experience some weirdness regarding using regex with django
I have following function in utils.py

from django.utils.text import wrap
import re

str = "wr: \n one bunny \n two bunny \n wr: three bunny \n
def do_regex(text):
lines = wrap(text, 55).split('\n')
for i, line in enumerate(lines):
cmp = re.compile(r'[wr:]$')
rgx = cmp.search(line)
if rgx:
line = "+%s" % line
lines[i] = line
else :
lines[i] = ">%s" % line
return '\n'.join(lines)
do_regex(str)


when calling do_regex() from views.py, I always get rgx null while
when I use django shell rgx will have value when match to regex that I
declare in cmp var
How to fix my regex so it can work inside views.py?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: passing template variable to templatetags

2009-06-21 Thread Joru

Is it possible to resolve tag value(in this is group.id) inside
templatetags(tag_model(parser,token)) function without having it
render in subclass of django.template.Node?
Please give me some solution

On Jun 20, 4:32 pm, Joru  wrote:
> Hi,
>
> Suppose I had templatetags
>  {% tag_model tags.tag as tags with group=group.id %)
>
> in my templatetags I define tag_model as a follow
>       def tag_model(parser, token):
>              bits = token.contents.split()
>              len_bits = len(bits)
>              name, value = bits[i].split('=')
>
> when I did {{ group.id }} this give me a id group value
> but when I do int(group.id) inside tag_model, the group.id is not well
> passed to the function, instead I get a group.id as a string
> How to get group.id value well passed inside tag_model?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



passing template variable to templatetags

2009-06-20 Thread Joru

Hi,

Suppose I had templatetags
 {% tag_model tags.tag as tags with group=group.id %)

in my templatetags I define tag_model as a follow
  def tag_model(parser, token):
 bits = token.contents.split()
 len_bits = len(bits)
 name, value = bits[i].split('=')

when I did {{ group.id }} this give me a id group value
but when I do int(group.id) inside tag_model, the group.id is not well
passed to the function, instead I get a group.id as a string
How to get group.id value well passed inside tag_model?


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