Re: Allow a limit_choices_to callable to accept the current model instances object

2018-09-25 Thread Tim Graham
There's a ticket with that feature request: 
https://code.djangoproject.com/ticket/25306

On Tuesday, September 25, 2018 at 6:25:38 PM UTC-4, Ochui Princewill wrote:
>
> Hello, 
>
> Am current working on a project and i want to filter the content of a 
> ForeignkeyField base on the current model object
>
> class Subscription(models.Model):
> user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete
> =models.CASCADE)
> plan = models.ForeignKey(Plan, on_delete=models.CASCADE)
> expires = models.DateField()
> created_at = models.DateTimeField(auto_now_add=True)
>
> class Profile(models.Model):
> user = models.OneToOneField(settings.AUTH_USER_MODEL, 
> on_delete=models.CASCADE, 
> editable=False)
> subscription = models.ForeignKey(Subscription, limit_choices_to={'user_id': 
> settings.AUTH_USER_MODEL}, on_delete=models.SET_NULL, null=True, blank=
> True)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5abc1695-ae5b-45c2-ac8f-c73d7c2d0be7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Allow a limit_choices_to callable to accept the current model instances object

2018-09-25 Thread Ochui Princewill
Hello, 

Am current working on a project and i want to filter the content of a 
ForeignkeyField base on the current model object

class Subscription(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
plan = models.ForeignKey(Plan, on_delete=models.CASCADE)
expires = models.DateField()
created_at = models.DateTimeField(auto_now_add=True)

class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, 
editable=False)
subscription = models.ForeignKey(Subscription, limit_choices_to={'user_id': 
settings.AUTH_USER_MODEL}, on_delete=models.SET_NULL, null=True, blank=True)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/531efff8-cdb2-431e-b0ba-602603ec828e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New member: Germano Carella. I need help with django, limit_choices_to and admin interface

2018-08-10 Thread germano carella

I found a tutorial!

I studied ForeignKey and how it works with sets... Now, I'll learn how 
to create a form and how to save the new data in set.


Thanks!



Il 09/08/2018 22:59, Julio Biason ha scritto:

Hi Germano,

When you use "ManyToMany", you're saying "any book can have any 
chapter and vice versa". That's obviously what you don't want. What 
you want is "A book has a closed set of chapters". This is done by 
thinking a bit on the other way with Django: Instead of saying "There 
is a list of chapters of this book", you say "The chapter belongs to a 
single book" with a foreign key:


class Book(models.Model):
   title = models.CharField(max_length=250)

class Chapters(models.Model):
   title = models.CharField(max_length=250)
   text = models.TextField()
   book = models.ForeignKey(Book)

Now a chapter can belong only to a book.

On Thu, Aug 9, 2018 at 4:34 PM, Germano Carella 
mailto:germano.care...@gmail.com>> wrote:


Hi,
I'm Germano from Italy. I'm new of django.
Probably this discussion has many many examples, but I can't find
my situation.
I have two models, Book and Chapters.
These are simple models, I need them only for educational purpose.

class Book(models.Model):
    title=models.CharField(max_length=250)
    chapters = models.ManyToManyField('Chapters')

class Chapters(models.Model):
    title_of_chapter = models.CharField(max_length=250)
    text=models.TextField()

Now, in admin interface I can add chapters on a new book and it
works fine.
So, whdn I try to add a second book I can see chapters of book I
added previously.

When I add a new book I want see only chapter of this book. List
must be empty if I'm adding a new book.
It's very simple, but I can't find a way to make it working.

I tried somethings, such as
chapters=
models.ManyToManyField('Chapters',limit_choices_to=Q('book__title'=title))
But this not works.
I know Chapters has book_set, that is the set of references for a
chapter.

There is a way to make it working?
-- 
You received this message because you are subscribed to the Google

Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users
<https://groups.google.com/group/django-users>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/2f104d64-50f4-433b-a764-be29d9a77f0c%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/2f104d64-50f4-433b-a764-be29d9a77f0c%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.




--
*Julio Biason*,Sofware Engineer
*AZION*  | Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51 
_99907 0554_

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto:django-users@googlegroups.com>.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEM7gE0rAfJPYbgKxgHCRYwVuAEBGQrz5X2WxOJdOW6mG%3DzK3Q%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAEM7gE0rAfJPYbgKxgHCRYwVuAEBGQrz5X2WxOJdOW6mG%3DzK3Q%40mail.gmail.com?utm_medium=email_source=footer>.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2cadbc8e-ccdc-2283-9a58-7097c6a4f010%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: New member: Germano Carella. I need help with django, limit_choices_to and admin interface

2018-08-09 Thread germano carella

Hi Julio,

Thanks, now is clear.

Ok, I created models correctly and createa book in admin interface. Now 
I can create chapters to add this book.


Now I want to learn how to create an interface that allows an user to 
add a new book, click on next button and add chapters to this book that 
is selected by default in book select list.


Can you point me in a tutorial, or document?

Thanks in advance,

Germano


Il 09/08/2018 22:59, Julio Biason ha scritto:

Hi Germano,

When you use "ManyToMany", you're saying "any book can have any 
chapter and vice versa". That's obviously what you don't want. What 
you want is "A book has a closed set of chapters". This is done by 
thinking a bit on the other way with Django: Instead of saying "There 
is a list of chapters of this book", you say "The chapter belongs to a 
single book" with a foreign key:


class Book(models.Model):
   title = models.CharField(max_length=250)

class Chapters(models.Model):
   title = models.CharField(max_length=250)
   text = models.TextField()
   book = models.ForeignKey(Book)

Now a chapter can belong only to a book.

On Thu, Aug 9, 2018 at 4:34 PM, Germano Carella 
mailto:germano.care...@gmail.com>> wrote:


Hi,
I'm Germano from Italy. I'm new of django.
Probably this discussion has many many examples, but I can't find
my situation.
I have two models, Book and Chapters.
These are simple models, I need them only for educational purpose.

class Book(models.Model):
    title=models.CharField(max_length=250)
    chapters = models.ManyToManyField('Chapters')

class Chapters(models.Model):
    title_of_chapter = models.CharField(max_length=250)
    text=models.TextField()

Now, in admin interface I can add chapters on a new book and it
works fine.
So, whdn I try to add a second book I can see chapters of book I
added previously.

When I add a new book I want see only chapter of this book. List
must be empty if I'm adding a new book.
It's very simple, but I can't find a way to make it working.

I tried somethings, such as
chapters=
models.ManyToManyField('Chapters',limit_choices_to=Q('book__title'=title))
But this not works.
I know Chapters has book_set, that is the set of references for a
chapter.

There is a way to make it working?
-- 
You received this message because you are subscribed to the Google

Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users
<https://groups.google.com/group/django-users>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/2f104d64-50f4-433b-a764-be29d9a77f0c%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/2f104d64-50f4-433b-a764-be29d9a77f0c%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.




--
*Julio Biason*,Sofware Engineer
*AZION*  | Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51 
_99907 0554_

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto:django-users@googlegroups.com>.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEM7gE0rAfJPYbgKxgHCRYwVuAEBGQrz5X2WxOJdOW6mG%3DzK3Q%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAEM7gE0rAfJPYbgKxgHCRYwVuAEBGQrz5X2WxOJdOW6mG%3DzK3Q%40mail.gmail.com?utm_medium=email_source=footer>.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/56a615c7-da95-c0b4-2079-a3b581e43c39%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: New member: Germano Carella. I need help with django, limit_choices_to and admin interface

2018-08-09 Thread Julio Biason
Hi Germano,

When you use "ManyToMany", you're saying "any book can have any chapter and
vice versa". That's obviously what you don't want. What you want is "A book
has a closed set of chapters". This is done by thinking a bit on the other
way with Django: Instead of saying "There is a list of chapters of this
book", you say "The chapter belongs to a single book" with a foreign key:

class Book(models.Model):
   title = models.CharField(max_length=250)

class Chapters(models.Model):
   title = models.CharField(max_length=250)
   text = models.TextField()
   book = models.ForeignKey(Book)

Now a chapter can belong only to a book.

On Thu, Aug 9, 2018 at 4:34 PM, Germano Carella 
wrote:

> Hi,
> I'm Germano from Italy. I'm new of django.
> Probably this discussion has many many examples, but I can't find
> my situation.
> I have two models, Book and Chapters.
> These are simple models, I need them only for educational purpose.
>
> class Book(models.Model):
> title=models.CharField(max_length=250)
> chapters = models.ManyToManyField('Chapters')
>
> class Chapters(models.Model):
> title_of_chapter = models.CharField(max_length=250)
> text=models.TextField()
>
> Now, in admin interface I can add chapters on a new book and it works fine.
> So, whdn I try to add a second book I can see chapters of book I added
> previously.
>
> When I add a new book I want see only chapter of this book. List must be
> empty if I'm adding a new book.
> It's very simple, but I can't find a way to make it working.
>
> I tried somethings, such as
> chapters= models.ManyToManyField('Chapters',limit_choices_to=Q('
> book__title'=title))
> But this not works.
> I know Chapters has book_set, that is the set of references for a chapter.
>
> There is a way to make it working?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/2f104d64-50f4-433b-a764-be29d9a77f0c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/2f104d64-50f4-433b-a764-be29d9a77f0c%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEM7gE0rAfJPYbgKxgHCRYwVuAEBGQrz5X2WxOJdOW6mG%3DzK3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


New member: Germano Carella. I need help with django, limit_choices_to and admin interface

2018-08-09 Thread Germano Carella
Hi,
I'm Germano from Italy. I'm new of django.
Probably this discussion has many many examples, but I can't find 
my situation.
I have two models, Book and Chapters.
These are simple models, I need them only for educational purpose.

class Book(models.Model):
title=models.CharField(max_length=250)
chapters = models.ManyToManyField('Chapters')

class Chapters(models.Model):
title_of_chapter = models.CharField(max_length=250)
text=models.TextField()

Now, in admin interface I can add chapters on a new book and it works fine.
So, whdn I try to add a second book I can see chapters of book I added 
previously.

When I add a new book I want see only chapter of this book. List must be 
empty if I'm adding a new book.
It's very simple, but I can't find a way to make it working.

I tried somethings, such as 
chapters= 
models.ManyToManyField('Chapters',limit_choices_to=Q('book__title'=title))
But this not works.
I know Chapters has book_set, that is the set of references for a chapter.

There is a way to make it working? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f104d64-50f4-433b-a764-be29d9a77f0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 2.1b1: Getting "unexpected keyword argument 'limit_choices_to'"

2018-07-05 Thread Axel Rau
Thanks Markus for the hint.
f3fa86a fixed the problem.

> Am 04.07.2018 um 17:11 schrieb Markus Holtermann  >:
> 
> Thanks for the report Axel. This seems to be the same issue as the one 
> reported in https://code.djangoproject.com/ticket/29449 
>  . A fix for this is coming with 
> the next pre release (beta 2 or RC1).


Axel
---
PGP-Key:29E99DD6  ☀  computing @ chaos claudius

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/131FDAB4-D482-488C-82DF-E549B0ECB066%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.


Re: 2.1b1: Getting "unexpected keyword argument 'limit_choices_to'"

2018-07-04 Thread Markus Holtermann
Thanks for the report Axel. This seems to be the same issue as the one 
reported in https://code.djangoproject.com/ticket/29449 . A fix for this is 
coming with the next pre release (beta 2 or RC1).

/Markus

On Wednesday, July 4, 2018 at 1:46:54 PM UTC+2, axel...@chaos1.de wrote:
>
> Hi, 
>
> I tried 2.1b1 with my 2.0.6 project and at got this error on startup: 
> —- 
> (erdb_d2.1+p3.6) axels-imac:ERDB2 ajr$ django-admin check 
> /usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/psycopg2/__init__.py:144:
>  
> UserWarning: The psycopg2 wheel package will be renamed from release 2.8; 
> in order to keep installing from binary please use "pip install 
> psycopg2-binary" instead. For details see: <
> http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. 
>   """) 
> Traceback (most recent call last): 
>   File "/usr/local/py_env/erdb_d2.1+p3.6/bin/django-admin", line 11, in 
>  
> sys.exit(execute_from_command_line()) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>  
> line 381, in execute_from_command_line 
> utility.execute() 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>  
> line 357, in execute 
> django.setup() 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/__init__.py",
>  
> line 24, in setup 
> apps.populate(settings.INSTALLED_APPS) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/apps/registry.py",
>  
> line 120, in populate 
> app_config.ready() 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/admin/apps.py",
>  
> line 24, in ready 
> self.module.autodiscover() 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/admin/__init__.py",
>  
> line 26, in autodiscover 
> autodiscover_modules('admin', register_to=site) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/utils/module_loading.py",
>  
> line 47, in autodiscover_modules 
> import_module('%s.%s' % (app_config.name, module_to_search)) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/importlib/__init__.py", 
> line 126, in import_module 
> return _bootstrap._gcd_import(name[level:], package, level) 
>   File "", line 994, in _gcd_import 
>   File "", line 971, in _find_and_load 
>   File "", line 955, in 
> _find_and_load_unlocked 
>   File "", line 665, in _load_unlocked 
>   File "", line 678, in exec_module 
>   File "", line 219, in 
> _call_with_frames_removed 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/auth/admin.py",
>  
> line 6, in  
> from django.contrib.auth.forms import ( 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/auth/forms.py",
>  
> line 63, in  
> class UserCreationForm(forms.ModelForm): 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/models.py",
>  
> line 256, in __new__ 
> apply_limit_choices_to=False, 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/models.py",
>  
> line 172, in fields_for_model 
> formfield = f.formfield(**kwargs) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
>  
> line 1016, in formfield 
> return super().formfield(**kwargs) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
>  
> line 956, in formfield 
> **kwargs, 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
>  
> line 418, in formfield 
> return super().formfield(**defaults) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
>  
> line 890, in formfield 
> return form_class(**defaults) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/fields.py",
>  
> line 213, in __init__ 
> super().__init__(**kwargs) 
> TypeError: __init__() got an unexpected keyword argument 
> 'limit_choices_to' 
> (erdb_d2.1+p3.6) axels-imac:ERDB2 ajr$ findp imit_choices_to 
> - - - 
> Seems to happen

Re: 2.1b1: Getting "unexpected keyword argument 'limit_choices_to'"

2018-07-04 Thread Jason
You might want to add that to the developers mailing list at 
https://groups.google.com/forum/#!forum/django-developers or make a bug 
report on the django issue tracker.  

If its working in 2.0, then there's a regression happening.

On Wednesday, July 4, 2018 at 7:46:54 AM UTC-4, axel...@chaos1.de wrote:
>
> Hi, 
>
> I tried 2.1b1 with my 2.0.6 project and at got this error on startup: 
> —- 
> (erdb_d2.1+p3.6) axels-imac:ERDB2 ajr$ django-admin check 
> /usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/psycopg2/__init__.py:144:
>  
> UserWarning: The psycopg2 wheel package will be renamed from release 2.8; 
> in order to keep installing from binary please use "pip install 
> psycopg2-binary" instead. For details see: <
> http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. 
>   """) 
> Traceback (most recent call last): 
>   File "/usr/local/py_env/erdb_d2.1+p3.6/bin/django-admin", line 11, in 
>  
> sys.exit(execute_from_command_line()) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>  
> line 381, in execute_from_command_line 
> utility.execute() 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>  
> line 357, in execute 
> django.setup() 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/__init__.py",
>  
> line 24, in setup 
> apps.populate(settings.INSTALLED_APPS) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/apps/registry.py",
>  
> line 120, in populate 
> app_config.ready() 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/admin/apps.py",
>  
> line 24, in ready 
> self.module.autodiscover() 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/admin/__init__.py",
>  
> line 26, in autodiscover 
> autodiscover_modules('admin', register_to=site) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/utils/module_loading.py",
>  
> line 47, in autodiscover_modules 
> import_module('%s.%s' % (app_config.name, module_to_search)) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/importlib/__init__.py", 
> line 126, in import_module 
> return _bootstrap._gcd_import(name[level:], package, level) 
>   File "", line 994, in _gcd_import 
>   File "", line 971, in _find_and_load 
>   File "", line 955, in 
> _find_and_load_unlocked 
>   File "", line 665, in _load_unlocked 
>   File "", line 678, in exec_module 
>   File "", line 219, in 
> _call_with_frames_removed 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/auth/admin.py",
>  
> line 6, in  
> from django.contrib.auth.forms import ( 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/auth/forms.py",
>  
> line 63, in  
> class UserCreationForm(forms.ModelForm): 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/models.py",
>  
> line 256, in __new__ 
> apply_limit_choices_to=False, 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/models.py",
>  
> line 172, in fields_for_model 
> formfield = f.formfield(**kwargs) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
>  
> line 1016, in formfield 
> return super().formfield(**kwargs) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
>  
> line 956, in formfield 
> **kwargs, 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
>  
> line 418, in formfield 
> return super().formfield(**defaults) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
>  
> line 890, in formfield 
> return form_class(**defaults) 
>   File 
> "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/fields.py",
>  
> line 213, in __init__ 
> super().__init__(**kwargs) 
> TypeError: __init__() got an unexpected keyword argument 
> 'limit_choices_to' 
> (erdb_d2.1+p3.6) axels-imac:ERDB2 ajr$ findp imit_choices_to 
> - - 

2.1b1: Getting "unexpected keyword argument 'limit_choices_to'"

2018-07-04 Thread Axel Rau
Hi,

I tried 2.1b1 with my 2.0.6 project and at got this error on startup:
—-
(erdb_d2.1+p3.6) axels-imac:ERDB2 ajr$ django-admin check
/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/psycopg2/__init__.py:144:
 UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in 
order to keep installing from binary please use "pip install psycopg2-binary" 
instead. For details see: 
<http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
Traceback (most recent call last):
  File "/usr/local/py_env/erdb_d2.1+p3.6/bin/django-admin", line 11, in 
sys.exit(execute_from_command_line())
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
 line 381, in execute_from_command_line
utility.execute()
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
 line 357, in execute
django.setup()
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/__init__.py",
 line 24, in setup
apps.populate(settings.INSTALLED_APPS)
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/apps/registry.py",
 line 120, in populate
app_config.ready()
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/admin/apps.py",
 line 24, in ready
self.module.autodiscover()
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/admin/__init__.py",
 line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/utils/module_loading.py",
 line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
  File "/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/importlib/__init__.py", 
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in _call_with_frames_removed
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/auth/admin.py",
 line 6, in 
from django.contrib.auth.forms import (
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/contrib/auth/forms.py",
 line 63, in 
class UserCreationForm(forms.ModelForm):
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/models.py",
 line 256, in __new__
apply_limit_choices_to=False,
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/models.py",
 line 172, in fields_for_model
formfield = f.formfield(**kwargs)
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
 line 1016, in formfield
return super().formfield(**kwargs)
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
 line 956, in formfield
**kwargs,
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/related.py",
 line 418, in formfield
return super().formfield(**defaults)
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
 line 890, in formfield
return form_class(**defaults)
  File 
"/usr/local/py_env/erdb_d2.1+p3.6/lib/python3.6/site-packages/django/forms/fields.py",
 line 213, in __init__
super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'limit_choices_to'
(erdb_d2.1+p3.6) axels-imac:ERDB2 ajr$ findp imit_choices_to
- - -
Seems to happen somewhere in Django code.

Any help appreciated,
Axel
---
PGP-Key:29E99DD6  ☀  computing @ chaos claudius

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/F654B9CE-9330-48C2-8C4D-F3C0BE8CA27D%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.


Re: limit_choices_to=function() not work in python-3.6+django-1.11.2

2017-06-28 Thread Tim Graham
The new ticket is https://code.djangoproject.com/ticket/28345.

On Wednesday, June 28, 2017 at 5:03:54 PM UTC-4, Tim Graham wrote:
>
> A new ticket is appropriate since the changes for the original ticket are 
> already released. Please include more explicit steps about how to reproduce 
> the issue -- it's difficult for me to tell exactly what the issue is from 
> the details you provided so far.
>
> On Wednesday, June 28, 2017 at 10:42:50 AM UTC-4, Drunkard Zhang wrote:
>>
>>
>>
>> On Wednesday, June 28, 2017 at 10:11:35 PM UTC+8, Drunkard Zhang wrote:
>>>
>>>
>>>
>>> On Wednesday, June 28, 2017 at 7:56:36 PM UTC+8, Tim Graham wrote:

 To get some insight, I'd try bisecting to find the Django commit where 
 the behavior changed:

 https://docs.djangoproject.com/en/dev/internals/contributing/triaging-tickets/#bisecting-a-regression


>>> After a whole day digging that, I found the commit changed the 
>>> behaviour: 6abd6c598ea23e0a962c87b0075aa2f79f9ead36, and the ticket: 
>>> https://code.djangoproject.com/ticket/27563
>>>
>>> I'm feeding back to upstream.
>>>

 Should I open a new regression report for this? 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/58e67f67-f060-44b1-892f-f80e3ad88376%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: limit_choices_to=function() not work in python-3.6+django-1.11.2

2017-06-28 Thread Tim Graham
A new ticket is appropriate since the changes for the original ticket are 
already released. Please include more explicit steps about how to reproduce 
the issue -- it's difficult for me to tell exactly what the issue is from 
the details you provided so far.

On Wednesday, June 28, 2017 at 10:42:50 AM UTC-4, Drunkard Zhang wrote:
>
>
>
> On Wednesday, June 28, 2017 at 10:11:35 PM UTC+8, Drunkard Zhang wrote:
>>
>>
>>
>> On Wednesday, June 28, 2017 at 7:56:36 PM UTC+8, Tim Graham wrote:
>>>
>>> To get some insight, I'd try bisecting to find the Django commit where 
>>> the behavior changed:
>>>
>>> https://docs.djangoproject.com/en/dev/internals/contributing/triaging-tickets/#bisecting-a-regression
>>>
>>>
>> After a whole day digging that, I found the commit changed the behaviour: 
>> 6abd6c598ea23e0a962c87b0075aa2f79f9ead36, and the ticket: 
>> https://code.djangoproject.com/ticket/27563
>>
>> I'm feeding back to upstream.
>>
>>>
>>> Should I open a new regression report for this? 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b3269e6d-2469-42ff-b51f-3870cba3170e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: limit_choices_to=function() not work in python-3.6+django-1.11.2

2017-06-28 Thread Drunkard Zhang


On Wednesday, June 28, 2017 at 10:11:35 PM UTC+8, Drunkard Zhang wrote:
>
>
>
> On Wednesday, June 28, 2017 at 7:56:36 PM UTC+8, Tim Graham wrote:
>>
>> To get some insight, I'd try bisecting to find the Django commit where 
>> the behavior changed:
>>
>> https://docs.djangoproject.com/en/dev/internals/contributing/triaging-tickets/#bisecting-a-regression
>>
>>
> After a whole day digging that, I found the commit changed the behaviour: 
> 6abd6c598ea23e0a962c87b0075aa2f79f9ead36, and the ticket: 
> https://code.djangoproject.com/ticket/27563
>
> I'm feeding back to upstream.
>
>>
>> Should I open a new regression report for this? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e9c16d82-d36d-41f3-826c-4844dfc8be61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: limit_choices_to=function() not work in python-3.6+django-1.11.2

2017-06-28 Thread Drunkard Zhang


On Wednesday, June 28, 2017 at 7:56:36 PM UTC+8, Tim Graham wrote:
>
> To get some insight, I'd try bisecting to find the Django commit where the 
> behavior changed:
>
> https://docs.djangoproject.com/en/dev/internals/contributing/triaging-tickets/#bisecting-a-regression
>
>
After a whole day digging that, I found the commit changed the behaviour: 
6abd6c598ea23e0a962c87b0075aa2f79f9ead36, and the ticket: 
https://code.djangoproject.com/ticket/27563

I'm feeding back to upstream.
 

> On Wednesday, June 28, 2017 at 7:10:35 AM UTC-4, Drunkard Zhang wrote:
>>
>> Hi, fellows:
>>
>> I was running python-3.4+django-1.9.13 previous, and upgrading to 
>> python-3.6+django-1.11.2, while testing, I found that my limit_choices_to 
>> function not working now, here's detail.
>>
>> I'm using a middleware to get current user who is accessing my site, and 
>> use it in limit_choices_to function, to provide different filter based on 
>> current user. This works great with python-3.4 + django-1.9.13; and using 
>> django-crispy-forms to render user forms.
>>
>> After upgraded to python-3.6+django-1.11, limit_choices_to function 
>> didn't called when I opened a USER EDIT FORM (by adding print() to the 
>> function), but it still works with django admin.
>>
>> So the question is:
>> 1. The difference of init procedures between django 1.9.13 and 1.11.2? 
>> Because 1.9.13 won't exec limit_choices_to function on init, while 1.11.2 
>> does.
>> 2. Where should I fix the problem? django init settings, my form, or even 
>> django-crispy-forms?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ce898186-ba03-4c32-b260-30ee93c5c722%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: limit_choices_to=function() not work in python-3.6+django-1.11.2

2017-06-28 Thread Tim Graham
To get some insight, I'd try bisecting to find the Django commit where the 
behavior changed:
https://docs.djangoproject.com/en/dev/internals/contributing/triaging-tickets/#bisecting-a-regression

On Wednesday, June 28, 2017 at 7:10:35 AM UTC-4, Drunkard Zhang wrote:
>
> Hi, fellows:
>
> I was running python-3.4+django-1.9.13 previous, and upgrading to 
> python-3.6+django-1.11.2, while testing, I found that my limit_choices_to 
> function not working now, here's detail.
>
> I'm using a middleware to get current user who is accessing my site, and 
> use it in limit_choices_to function, to provide different filter based on 
> current user. This works great with python-3.4 + django-1.9.13; and using 
> django-crispy-forms to render user forms.
>
> After upgraded to python-3.6+django-1.11, limit_choices_to function didn't 
> called when I opened a USER EDIT FORM (by adding print() to the function), 
> but it still works with django admin.
>
> So the question is:
> 1. The difference of init procedures between django 1.9.13 and 1.11.2? 
> Because 1.9.13 won't exec limit_choices_to function on init, while 1.11.2 
> does.
> 2. Where should I fix the problem? django init settings, my form, or even 
> django-crispy-forms?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9924fb7c-e67f-4b0e-9589-9a8e2f8b549f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


limit_choices_to=function() not work in python-3.6+django-1.11.2

2017-06-28 Thread Drunkard Zhang
Hi, fellows:

I was running python-3.4+django-1.9.13 previous, and upgrading to 
python-3.6+django-1.11.2, while testing, I found that my limit_choices_to 
function not working now, here's detail.

I'm using a middleware to get current user who is accessing my site, and 
use it in limit_choices_to function, to provide different filter based on 
current user. This works great with python-3.4 + django-1.9.13; and using 
django-crispy-forms to render user forms.

After upgraded to python-3.6+django-1.11, limit_choices_to function didn't 
called when I opened a USER EDIT FORM (by adding print() to the function), 
but it still works with django admin.

So the question is:
1. The difference of init procedures between django 1.9.13 and 1.11.2? 
Because 1.9.13 won't exec limit_choices_to function on init, while 1.11.2 
does.
2. Where should I fix the problem? django init settings, my form, or even 
django-crispy-forms?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/720cfbc1-d941-4e3b-8cbe-3a7eae116f6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with limit_choices_to and filtering foreign key

2014-08-01 Thread Hilde Rafaelsen
I have two models, ReqForChange(models.Model) and RfcStatus(models.Model).

class ReqForChange(models.Model):
rfc = models.AutoField (primary_key=True)
   user = models.ForeignKey(User, verbose_name="Requested by")
  status = models.ForeignKey(Status, verbose_name="RfC State")
   effectOnUsers = models.NullBooleanField("Effect", blank=True, 
null=True) 



class RfcStatus(models.Model):
rfcd = models.AutoField (primary_key=True)
rfcStatusDateCreated = models.DateField("Created date", 
default=datetime.now())
rfc_details = models.ForeignKey(ReqForChange, 
limit_choices_to={'effectOnUsers': True}, blank=True, null=True)


In my admin page I want the user to register a new ReqForChange  and when 
the user open the RfcStatus the dropdown menu for the field effectOnUsers 
shall only display items where effectOnUsers is set to True. This do not 
work and I can't understand why? I have tried the limit_choice_to on the 
User field in the ReqForChange model, and that works fine.

I hope someone can give me a hint on how I can manage to filter values for 
my rfc_details field. I run django 1.6

Best regards,

Hilde T L Rafaelsen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24dee8af-5686-45db-af1b-26fa17d91125%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django limit_choices_to - ForeignKey

2014-07-31 Thread cmawebsite
If you are using the admin:

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_choice_field

Otherwise, you'll need to dynamically create that field or the entire form.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bdd0f989-c442-40fd-8d97-e6f282525ca9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django limit_choices_to - ForeignKey

2014-07-23 Thread Ganea Ionut
Hello there,

Recently i've been tasked with using the 'limit_choices_to' attribute of a 
ForeignKey field, in order to limit choices.

My models are like this (params -> max_length, choices, etc):

class DeviceFeatures(models.Model):

# declare choices here: feature_choices #

features = models.CharField(params)
namespace = models.CharField(params)

class Device(models.Model):

jid = models.CharField(params)
name = models.CharField(params)
features = models.ManyToManyField(DeviceFeatures)

class DeviceMember(models.Model):

device = models.ForeignKey(Device)
features = models.ForeignKey(DeviceFeatures, 
limit_choices_to={"feature__in": [str(feature) for feature in 
device.features.all()]}) (theory)

What i would like to know, is how i can access the features of a device, 
inside of the DeviceMember model. More exactly, i want only the features of 
the device that DeviceMember - ForeignKey attribute points out to.

I've been studying for some hours how limit_choices_to works...and i know 
this is how i'm supposed to use it, i just can't figure out how to access 
the features of the foreign key device.

thank you all.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/996cc793-576b-4742-8be4-c101dbc92fc1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Foreign key field with limit_choices_to

2014-06-04 Thread dmbarbour87


class ProductGroup(models.Model):
group_sku = models.CharField(unique=True, max_length=255)
brand = models.CharField(max_length=255)
...

class Product(models.Model):
product_sku = models.CharField(unique=True, max_length=255)
color = models.CharField(max_length=255)
size = models.CharField(max_length=255)
product = models.ForeignKey(Product, 
limit_choices_to=Q(group_sku__in=product_sku))
...

I'm importing my data to Django from an XML file via a python script.

group_sku comes in the format "GROUP123"

product_sku comes in the format "GROUP123-BLUE-M" (or similar) and there 
are multiple products in each group

How do I define the foreign key relationship so that each Product is linked 
to its respective ProductGroup? Or feel free to tell me if I'm going about 
this the complete wrong way.

Using Django 1.6.5, Python 2.7, and MySQL

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7b972d02-f9cf-4bd2-a453-43474bf920ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ManyToManyField causes invalid form when limit_choices_to argument set

2014-04-30 Thread rgreene
Solved! It turned out the problem only occurred trying to uncheck the last 
checkbox. I needed to set blank=True on the ManyToManyField.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/045d2628-55da-4353-9f46-8893243161b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ManyToManyField causes invalid form when limit_choices_to argument set

2014-04-30 Thread rgreene
Good day,

This is a somewhat contrived example, but I'm having the same problem in a 
real project.

Assuming continents have many countries, and countries can belong to many 
continents, I have a continent_country "junction" table in the database and 
am using ManyToManyField as follows...

Models:
*class Country(models.Model):*
*country_id = models.AutoField(primary_key=True)*
*country_name = models.CharField(max_length=200)*

*class Meta:*
*managed = False*
*db_table = 'country'*

*def __unicode__(self):*
*return '%s' % (self.country_name)*

*class Continent(models.Model):*
*continent_id = models.AutoField(primary_key=True)*
*continent_name = models.CharField(max_length=200)*

*country = models.ManyToManyField(Country, 
db_table='continent_country', limit_choices_to=Q(country_id__exact=1))*

*class Meta:*
*managed = False*
*db_table = 'continent'*

Form:
*class ContinentForm(ModelForm):*
*class Meta:*
*model = Continent*
*widgets = {'country': CheckboxSelectMultiple}*

Using this form, everything saves as expected if I remove the 
limit_choices_to=Q(country_id__exact=1)argument. However, using the form 
with the ManyToManyField configured as shown causes the form to be returned 
with is_valid=False in the POST, indicating that field country is required.

I traced into the django code for a bit, but as a relative rookie got 
somewhat lost! Why does limiting the list prevent django from setting the 
country? How to work around this? Any ideas greatly appreciated...

Thanks in advance,
Randal

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aa1249ca-dc1b-4abb-91e8-45a174a8506f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: .annotate() in limit_choices_to?

2013-05-28 Thread galgal


I wrote some code, but it returns doubled entries if there's no annotate:

price_variants = models.ManyToManyField(
ProductPriceVariant, verbose_name=_(u'price variants'),
limit_choices_to=Q(translation__language__iexact=get_language()[:2]) & 
Q(
translation__product__subproducts__isnull=False))


On Tuesday, May 28, 2013 5:44:57 PM UTC+2, galgal wrote:
>
> Is it possible to put, somehow, *.annotate()* method into M2M *
> limit_choices_to*?
> I need to limit my choices to that query:
>
> *
> cls.objects.annotate(subproducts_num=models.Count('subproducts')).filter(subproducts_num__gt=0)
> *
>
>
> Any ideas?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




.annotate() in limit_choices_to?

2013-05-28 Thread galgal
Is it possible to put, somehow, *.annotate()* method into M2M *
limit_choices_to*?
I need to limit my choices to that query:

*
cls.objects.annotate(subproducts_num=models.Count('subproducts')).filter(subproducts_num__gt=0)
*


Any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Test limit_choices_to

2013-05-28 Thread galgal
Is there any way to test if my *limit_choices_to* argument is working as I 
expect? How can I test that in unit test?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: ManyToManyField limit_choices_to that instance via Django admin.

2011-06-07 Thread Micky Hulse
Hi Ryan! Thanks so much for the reply, I really appreciate the help. :)

On Tue, Jun 7, 2011 at 12:17 PM, Ryan <ryan.osb...@live.co.uk> wrote:
> This is possible, but I'm not sure if you could do it via limit_choices_to.
> The admin docs shows how to accomplish this here:

Oooh, interesting. I will experiment with that solution. Thanks for
pointing me in the right direction.

I will post back here if I code something worth sharing. :D

Thanks again!

Cheers,
Micky

-- 
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: ManyToManyField limit_choices_to that instance via Django admin.

2011-06-07 Thread Ryan
This is possible, but I'm not sure if you could do it via limit_choices_to.  
The admin docs shows how to accomplish this here: 
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_manytomany

Ryan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ZlhkM0JHY3dkbTRK.
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.



ManyToManyField limit_choices_to that instance via Django admin.

2011-06-06 Thread mhulse
Hello,

Here's some example code:

[code]

class Creative(...):

file2 = models.ManyToManyField('Asset', ...)

class Asset(...):
file = models.FileField(...)

[/code]

Can I use limit_choices_to to limit "Asset" to only the files that were 
uploaded by the currently viewed "Creative" instance?

In other words, if an uploaded file was not uploaded by the current 
instance, then I do not want to show it in the admin M2M choice filed.

Does that make sense?

I have googled around, but I have not had any luck implementing a solid 
solution. Any tips?

Thanks so much!

Cheers,
Micky

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/MlhzZ1lkS0N5WElK.
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: limit_choices_to (or some other way) to filter ForeignKey choices based on current model field

2011-04-19 Thread Derek
On Apr 16, 7:29 pm, Aljoša Mohorović <aljosa.mohoro...@gmail.com>
wrote:
> if i have something like this:
> ===
> class MyModel(models.Model):
>     name  = models.CharField(max_length=255)
>
> class OtherModel(models.Model):
>     name  = models.CharField(max_length=255)
>     mymodel = models.ForeignKey(MyModel)
>
> class MyModelItem(models.Model):
>     mymodel = models.ForeignKey(MyModel)
>     other = models.ForeignKey(OtherModel, null=True, blank=True)
> ===
>
> how can i use limit_choices_to (or some other way) to filter
> ForeignKey choices based on current model field?
> basically, how can i do:
>     other = models.ForeignKey(OtherModel, null=True, blank=True,
> limit_choices_to={'mymodel': 'self.mymodel'})
>
> any options works for me (overwriting admin.TabularInline or form for
> TabularInline).
> thanks for any info.

Have a look at:
http://stackoverflow.com/questions/1387431/django-model-modelform-how-to-get-dynamic-choices-in-choicefield
or
http://stackoverflow.com/questions/3419997/creating-a-dynamic-choice-field

If you want to change a live form where items in combobox B depend on
an item selected in combobox A, then you will need to use custom
javascript (and there are a ton of examples on the web using, for
example, jQuery).

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



limit_choices_to (or some other way) to filter ForeignKey choices based on current model field

2011-04-16 Thread Aljoša Mohorović
if i have something like this:
===
class MyModel(models.Model):
name  = models.CharField(max_length=255)

class OtherModel(models.Model):
name  = models.CharField(max_length=255)
mymodel = models.ForeignKey(MyModel)

class MyModelItem(models.Model):
mymodel = models.ForeignKey(MyModel)
other = models.ForeignKey(OtherModel, null=True, blank=True)
===

how can i use limit_choices_to (or some other way) to filter
ForeignKey choices based on current model field?
basically, how can i do:
other = models.ForeignKey(OtherModel, null=True, blank=True,
limit_choices_to={'mymodel': 'self.mymodel'})

any options works for me (overwriting admin.TabularInline or form for
TabularInline).
thanks for any info.

Aljosa

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



ManyToMany using through and limit_choices_to

2010-11-22 Thread Ferran
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

I've seen on the docs that is not possible to use limit_choices_to with
a ManyToMany relationship using intermediate tables with through parameter.

I need to have an "ordered" ManyToMany relationship, and i'm using an
intermediate table to achieve this, but i also need to ensure we can't
have more than 5 entries; can anybody help me to figure how can i solve
this out?

Thank you,
- -- 
Abordemos el parlamento! -- http://pirata.cat
En democracia, dos Belén Esteban valen más que tú
Di NO al top-posting!
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBCAAGBQJM6mfZAAoJEAWOKfEESaOwE6AQAIW9nnGciPk3hsuwkLH8NAtC
6DSZ7d3MM7akxrw8fOezAZKf0vbUyFP2wkVmuPXrpr/fYEMUIlC6PWb8NaSfiDlI
ywhX3ao0ZJIjw/Y3rjrYWmX5Yn9Tg9Fx9HXAo+sCsFY0JwE3oBWk7rNhVce1UZwu
p6yK5WRe0kEX3SZT81nb0XGyQNUZaW27xQ9FTEIMKbKLEB5r1HoMqsagASuQXCH5
OUVsoRI33dRhkxM1blpZYDbZSZFArHd9QEmTEy2wu6f++0GUKNrRDoJqZbbHSBTD
6zd7bIdmmNia5aILbOWWLkjCm5mO70i2a3w8s4jlNYsjhe1KmOUUWyDkzWSKmMlD
uSzP6u7RtbnwFatwZ4fBA8Xeq5b+Cok4aADN18sEB1XiSX1LOEbREoeBSs/WvBZ+
jxTC14HI9S53AU9PAjdMYhZHe5DFAcAy7LJphjWHS3WXesM8sXYDiCzcebFCkU29
WnN6lt8ef9tugCAhyjnCzi77gGT5+WIBLhaHEhpF/b7X3rds+vxiUYDBZiakQG07
BKuUuERpPPy9o/dUFjcXrWcAIbu07wc191Wolou1NGx4RtbKjO8oohuzzlHYsWs2
/L1aB8sPENUUC3XGRoD2Cq49ugBsYxjm1NBZL9eayyrXkY0DX9Ry0Xxw80AquHVk
KPjbSrxVkV6/puLVT32c
=uObP
-END PGP SIGNATURE-

-- 
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=en.



Re: How to dynamically set limit_choices_to for ManyToManyField using values from an instance?

2010-06-04 Thread Massimiliano della Rovere
Thanks Scott,
I have one doubt though: I need a bound form to properly set the queryset.
Using your method I'd use an unbound form, am I wrong?

On Fri, Jun 4, 2010 at 14:33, Scott Gould <zinck...@gmail.com> wrote:
> Create a ModelForm for your model (A), set the queryset to what you
> want on the appropriate field (n), and then register that ModelForm
> for admin use in your admins.py.
>
> Regards
> Scott
>
>
> On Jun 4, 6:14 am, Massimiliano della Rovere
> <massimiliano.dellarov...@gmail.com> wrote:
>> When displayed in the Admin interfaces, I'd like to filter the values
>> of n, so that instances of N already linked to other instances of A
>> sharing the same instance of o are not shown:
>> so when you edit an instance of A (let's call it "a"), you see only
>> the instances of n in use by a and the unsed ones (in the context of
>> o).
>>
>> The problem is that I am not allowd to write self.choices_for_n()
>>
>> Does anybody know any solution for this?
>>
>> class A(models.Model):
>>         o = models.ForeignKey(O)
>>         p = models.ManyToManyField(P)
>>         n = models.ManyToManyField(N, limit_choices_to=self.choices_for_n())
>>
>>         def choices_for_n(self):
>>                 unwanted = []
>>                 for z in self.o.z_set.all():
>>                         if z.id == self.id:
>>                                 continue
>>                         unwanted += [z.id for z in z.n]
>>                 for n in N.objects.exclude(id__in=unwanted):
>>                         yield n.id
>
> --
> 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=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=en.



Re: How to dynamically set limit_choices_to for ManyToManyField using values from an instance?

2010-06-04 Thread Scott Gould
Create a ModelForm for your model (A), set the queryset to what you
want on the appropriate field (n), and then register that ModelForm
for admin use in your admins.py.

Regards
Scott


On Jun 4, 6:14 am, Massimiliano della Rovere
<massimiliano.dellarov...@gmail.com> wrote:
> When displayed in the Admin interfaces, I'd like to filter the values
> of n, so that instances of N already linked to other instances of A
> sharing the same instance of o are not shown:
> so when you edit an instance of A (let's call it "a"), you see only
> the instances of n in use by a and the unsed ones (in the context of
> o).
>
> The problem is that I am not allowd to write self.choices_for_n()
>
> Does anybody know any solution for this?
>
> class A(models.Model):
>         o = models.ForeignKey(O)
>         p = models.ManyToManyField(P)
>         n = models.ManyToManyField(N, limit_choices_to=self.choices_for_n())
>
>         def choices_for_n(self):
>                 unwanted = []
>                 for z in self.o.z_set.all():
>                         if z.id == self.id:
>                                 continue
>                         unwanted += [z.id for z in z.n]
>                 for n in N.objects.exclude(id__in=unwanted):
>                         yield n.id

-- 
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=en.



How to dynamically set limit_choices_to for ManyToManyField using values from an instance?

2010-06-04 Thread Massimiliano della Rovere
When displayed in the Admin interfaces, I'd like to filter the values
of n, so that instances of N already linked to other instances of A
sharing the same instance of o are not shown:
so when you edit an instance of A (let's call it "a"), you see only
the instances of n in use by a and the unsed ones (in the context of
o).

The problem is that I am not allowd to write self.choices_for_n()

Does anybody know any solution for this?

class A(models.Model):
o = models.ForeignKey(O)
p = models.ManyToManyField(P)
n = models.ManyToManyField(N, limit_choices_to=self.choices_for_n())

def choices_for_n(self):
unwanted = []
for z in self.o.z_set.all():
if z.id == self.id:
continue
unwanted += [z.id for z in z.n]
for n in N.objects.exclude(id__in=unwanted):
yield n.id

-- 
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=en.



Re: Need limit_choices_to help

2010-03-20 Thread Walt
Is this the type of solution you have in mind?

http://tinyurl.com/yaqjfx4


Walt

-~

-- 
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=en.



Re: Need limit_choices_to help

2010-03-19 Thread bax...@gretschpages.com
Looking at this more, I think I may have more of a logic problem

I think Play can't have any idea of Game roster, because until it's
been saved it has no idea what game it's related to. So maybe what I
need is a way to dynamically fill the player field on Play, after game
has been selected. Tips?

-- 
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=en.



Need limit_choices_to help

2010-03-19 Thread bax...@gretschpages.com
I've got a Players model
I've got a Game models with roster, a M2M relationship with players,
to select the players actually playing in that particular game
And I've got a Play model with a foreignkey to Players. What I want is
to limit the list of players to the ones that are actually on the
roster for that game.

In my head, it should be something like
playmaker   = models.ForeignKey(Player, limit_choices_to=
{'id': 'game__roster'},

Or am I looking at it all wrong? Should I build a choice list from
roster on the fly and use that? OR can I just foreignKey straight to
Game__roster?

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=en.



Re: limit_choices_to a value on a field in the same model

2010-03-14 Thread Brandon Taylor
Walt, you're a lifesaver!

Many thanks for the great example. I only made a couple of minor
tweeks:

class AgencyForm(forms.ModelForm):
class Meta:
model = Agency

def __init__(self, *args, **kwargs):
super(AgencyForm, self).__init__(*args, **kwargs)
if self.instance.id:
if self.instance.state:
counties =
County.objects.filter(us_state=self.instance.state)
county_field = self.fields['counties'].widget
county_choices = []
if counties is None:
county_choices.append(('', '-'))
for county in counties:
county_choices.append((county.id, county.name))
county_field.choices = county_choices

Kind regards,
Brandon

On Mar 14, 8:23 am, Walt  wrote:
> Here is an idea of what your forms.py should contain:
>
> class AgencyForm(ModelForm):
>
>     class Meta:
>         model = Agency
>
>     def __init__(self, *args, **kwargs):
>         super(AgencyForm, self).__init__(*args, **kwargs)
>         if self.instance.id:
>             if self.instance.state_id:
>                 counties =
> County.objects.filter(state=self.instance.state_id)
>
>                 county_field = self.fields['counties'].widget
>                 county_choices = []
>                 county_choices.append(('', '--'))
>                 for county in counties:
>                     county_choices.append((county.id, county.name))
>                     county_field.choices = county_choices
>
> Then in admin.py, make sure you have:
>
> class AgencyAdmin(admin.ModelAdmin):
>     form = AgencyForm
>
> Hope this helps,
> Walt
>
> -~

-- 
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=en.



Re: limit_choices_to a value on a field in the same model

2010-03-14 Thread Walt
Here is an idea of what your forms.py should contain:

class AgencyForm(ModelForm):

class Meta:
model = Agency

def __init__(self, *args, **kwargs):
super(AgencyForm, self).__init__(*args, **kwargs)
if self.instance.id:
if self.instance.state_id:
counties =
County.objects.filter(state=self.instance.state_id)

county_field = self.fields['counties'].widget
county_choices = []
county_choices.append(('', '--'))
for county in counties:
county_choices.append((county.id, county.name))
county_field.choices = county_choices


Then in admin.py, make sure you have:

class AgencyAdmin(admin.ModelAdmin):
form = AgencyForm



Hope this helps,
Walt

-~

-- 
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=en.



limit_choices_to a value on a field in the same model

2010-03-13 Thread Brandon Taylor
Evening Everyone,

I have a model "Agency" with "state" as a foreign key and "counties"
as a many-to-many.
County has a foreign key to "state"

I would like to limit the County choices in Django admin to the state
of the Agency being edited, but, I can't seem to find the right place
to get an instance of the Agency being edited so I can override the
queryset for the many-to-many.

I've search quite a few posts, but can't find one with a working
example. Does anyone know where I might be able to find a good example
of this?

TIA,
Brandon

-- 
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=en.



Re: Can I use request.user, in the limit_choices_to filter in Model class?

2010-02-25 Thread zinckiwi
> I need to filter a field by a UserProfile function, i.e. how can I do
> something like this?
>
> class Paquet(models.Model):
>     ...
>     profiles = models.ManyToManyField(UserProfile, limit_choices_to =
> {'country': request.user.userprofile.country})

I'd put that restriction inside the ModelForm that derives from
Paquet, rather than into the model itself. I wouldn't even know how to
go about getting the current Request to the model, and there's a
reason for that: not a good idea!

Likewise, in the ModelForm, you won't have native access to the
current request. You're best off passing in request.user when you
instantiate the form.

Regards
Scott

-- 
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=en.



Can I use request.user, in the limit_choices_to filter in Model class?

2010-02-24 Thread Luis Gonzalez
I need to filter a field by a UserProfile function, i.e. how can I do
something like this?

class Paquet(models.Model):
...
profiles = models.ManyToManyField(UserProfile, limit_choices_to =
{'country': request.user.userprofile.country})

Thanks in advance.

-- 
___
Luis González Medina
http://djangotips.blogspot.com
http://konatufe.blogspot.com
http://twitter.com/konatufe

-- 
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=en.



Re: error with limit_choices_to with complex queries (Q object) and raw_id_fields

2009-10-13 Thread Russell Keith-Magee

On Tue, Oct 13, 2009 at 10:43 PM, fsaintma
<frederic.saintmar...@gmail.com> wrote:
>
> hello
>
> I have a model.py like this :
>
> class secondaryGroup(models.Model):
>   id = models.AutoField(primary_key = True)
>   idGroup = models.ForeignKey(Group,db_column =
> 'idGroup',verbose_name = 'Groupe',limit_choices_to = Q(state='valid')
> | Q(state='modify'))
>   idUser = models.ForeignKey(User,db_column = 'idUser',verbose_name =
> 'Utilisateur',limit_choices_to = Q(state='valid') | Q(state='modify'))
>
> and in admin.py :
>
> class SecondaryGroupAdmin(admin.ModelAdmin):
>   form = SecondaryGroupAdminForm
>   list_display = ('idUser','idGroup')
>   raw_id_fields = ('idUser','idGroup',)
>
> and I obtain this error in Admin edit form :
>
> Caught an exception while rendering: 'Q' object has no attribute
> 'items'

I presume you are the "anonymous" who opened ticket #12024. You may
have noticed that this ticket has been reopened - Karen Tracey pointed
me at some documentation that points out that I was mistaken in saying
this was user error. It appears that you have found a bug. Apologies
for the confusion.

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



error with limit_choices_to with complex queries (Q object) and raw_id_fields

2009-10-13 Thread fsaintma

hello

I have a model.py like this :

class secondaryGroup(models.Model):
   id = models.AutoField(primary_key = True)
   idGroup = models.ForeignKey(Group,db_column =
'idGroup',verbose_name = 'Groupe',limit_choices_to = Q(state='valid')
| Q(state='modify'))
   idUser = models.ForeignKey(User,db_column = 'idUser',verbose_name =
'Utilisateur',limit_choices_to = Q(state='valid') | Q(state='modify'))

and in admin.py :

class SecondaryGroupAdmin(admin.ModelAdmin):
   form = SecondaryGroupAdminForm
   list_display = ('idUser','idGroup')
   raw_id_fields = ('idUser','idGroup',)

and I obtain this error in Admin edit form :

Caught an exception while rendering: 'Q' object has no attribute
'items'

Can I Help me ?

Thanks in advance.

Bye.

--~--~-~--~~~---~--~~
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: limit_choices_to & get_sql()

2009-09-23 Thread Nicolas Steinmetz

On 22 sep, 23:31, Daniel Roseman <dan...@roseman.org.uk> wrote:
> Seems like you're looking at the ForeignKey documentation. The
> reference to get_sql() is confusing and very out of date on that page
> - Q objects don't have such a method, although they may have done back
> before the merge of queryset-refactor before version 1.0 was released.
>
> Anyway, the syntax is simple:
>     limit_choices_to = {'dnstype': 2}

That's it, thanks.

Indeed, I misunderstood the doc here :
http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey

Have a nice day,
Nicolas
--~--~-~--~~~---~--~~
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: limit_choices_to & get_sql()

2009-09-22 Thread Daniel Roseman

On Sep 22, 10:16 pm, Nicolas Steinmetz <nsteinm...@gmail.com> wrote:
> Hello,
>
> I would like to present only a subset of a given models. But so far,
> in the admin, I have no value whereas there should be some.
>
> I tried several syntax but did not find the right one.
>
> Here are my implicated (and simplified) models :
>
> class Dns(models.Model):
>     """
>     DNS description
>     """
>     TYPEDNS_CHOICES = (
>         ('1', 'Reference'),
>         ('2', 'Normal'),
>     )
>     name = models.CharField(blank=True, max_length=100)
>     dnstype = models.CharField(max_length=100,
> choices=TYPEDNS_CHOICES)
>
> class Url(models.Model):
>     """
>     Url description
>     """
>     name = models.CharField(blank=True, max_length=100)
>     [...]
>     cnamevalue = models.ForeignKey(Dns, limit_choices_to = {'dns':
> 'get_sql(Dns.dnstype="2")'}, blank=True)
>
> Could someone explain me what is the right syntax ?
>
> I could use formfield_for_foreignkey for admin contrib but I would
> prefer using limit_choices_to that I see as a native solution.
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> Thanks,
> Nicolas

Seems like you're looking at the ForeignKey documentation. The
reference to get_sql() is confusing and very out of date on that page
- Q objects don't have such a method, although they may have done back
before the merge of queryset-refactor before version 1.0 was released.

Anyway, the syntax is simple:
limit_choices_to = {'dnstype': 2}
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



limit_choices_to & get_sql()

2009-09-22 Thread Nicolas Steinmetz

Hello,

I would like to present only a subset of a given models. But so far,
in the admin, I have no value whereas there should be some.

I tried several syntax but did not find the right one.

Here are my implicated (and simplified) models :

class Dns(models.Model):
"""
DNS description
"""
TYPEDNS_CHOICES = (
('1', 'Reference'),
('2', 'Normal'),
)
name = models.CharField(blank=True, max_length=100)
dnstype = models.CharField(max_length=100,
choices=TYPEDNS_CHOICES)

class Url(models.Model):
"""
Url description
"""
name = models.CharField(blank=True, max_length=100)
[...]
cnamevalue = models.ForeignKey(Dns, limit_choices_to = {'dns':
'get_sql(Dns.dnstype="2")'}, blank=True)

Could someone explain me what is the right syntax ?

I could use formfield_for_foreignkey for admin contrib but I would
prefer using limit_choices_to that I see as a native solution.

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey

Thanks,
Nicolas

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

2009-08-01 Thread Daniele Procida

On Sat, Aug 1, 2009, Ramiro Morales  wrote:

>If you need this for the admin app and are using Django 1.1 read about
>the formfield_for_foreignkey ModelAdmin method:
>
>http://docs.djangoproject.com/en/dev/ref/contrib/admin/
>#django.contrib.admin.ModelAdmin.formfield_for_foreignkey
>
>you can write your own and further filter the queryset used for
>the FK field UI there, an example is included in the documentation

Thanks, I hadn't seen formfield_for_foreignkey before.

Part of that example goes does this:

Car.objects.filter(owner=request.user)

using the User instance as the basis for filtering. How could I refer to
the current instance of the model, to use that for filtering? 

In my case the model is Person, and field I want to get the choices from
is Entities.people (its related_name). So it owuld be something like:

Entities.objects.filter(people=[this instance of Person])

Daniele


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

2009-08-01 Thread Ramiro Morales

On Sat, Aug 1, 2009 at 12:05 PM, Daniele
Procida wrote:
>
> I am trying to set up a model.
>
> A Person has a ManyToMany relationship with Entities. One of those
> relationships is special - we can capture that with a ForeignKey
> relationship to Entity.
>
> But, I want to limit the choices for that special relationship to
> Entities that the person already has a relationship with, by using a:
>

If you need this for the admin app and are using Django 1.1 read about
the formfield_for_foreignkey ModelAdmin method:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey

you can write your own and further filter the queryset used for
the FK field UI there, an example is included in the documentation.

HTH

-- 
Ramiro Morales
http://rmorales.net

PyCon 2009 Argentina - Vie 4 y Sab 5 Setiembre
Buenos Aires, Argentina
http://ar.pycon.org/2009/about/

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



limit_choices_to

2009-08-01 Thread Daniele Procida

I am trying to set up a model. 

A Person has a ManyToMany relationship with Entities. One of those
relationships is special - we can capture that with a ForeignKey
relationship to Entity.

But, I want to limit the choices for that special relationship to
Entities that the person already has a relationship with, by using a:

   limit_choices_to  = {field: value},


So, I have tried various things that look like this:

class Person(models.Model):
entities = models.ManyToManyField(
Entity, 
related_name = 'people', 
through ='Membership',
)
home_entity = models.ForeignKey(
Entity, 
related_name = 'people_home', 
limit_choices_to  = {'people': person},
)

but I can't get the limit_choices_to dictionary right (obviously, it's
not going to be literally {'people': person}).

What should I be doing here?

Thanks,

Daniele


--~--~-~--~~~---~--~~
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: ManyToMany field and limit_choices_to

2009-05-16 Thread adrian

pilot error, no need to reply

On May 16, 10:41 am, adrian <adrian...@gmail.com> wrote:
> I am creating a view to edit a model that has a ManyToMany field.
> The field is defined as:
>
> performer = models.ManyToManyField(Entity, limit_choices_to=
> {'role__exact':'PER'})
>
> Entity is a table of persons or organizations.   Some of them are
> performers and some are not (distinguished by "role").
>
> I create a form from a valid instance of the model in the usual way
> using modelform. The correct set of POSSIBLE performers is shown but
> the ACTUAL performers are not highlighted (none are highlighted).
> So if the form is submitted with no changes it causes an error since
> performers is a required field.
>
> If I remove limit_choices_to, the set of entities shown is not correct
> (includes non-performers) but the performers currently saved in the
> instance ARE correctly highlighted.
>
> This seems like a bug but perhaps I have misunderstood what is
> supposed to happen.    And is there a workaround?
>
> 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-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
-~--~~~~--~~--~--~---



ManyToMany field and limit_choices_to

2009-05-16 Thread adrian


I am creating a view to edit a model that has a ManyToMany field.
The field is defined as:

performer = models.ManyToManyField(Entity, limit_choices_to=
{'role__exact':'PER'})

Entity is a table of persons or organizations.   Some of them are
performers and some are not (distinguished by "role").

I create a form from a valid instance of the model in the usual way
using modelform. The correct set of POSSIBLE performers is shown but
the ACTUAL performers are not highlighted (none are highlighted).
So if the form is submitted with no changes it causes an error since
performers is a required field.

If I remove limit_choices_to, the set of entities shown is not correct
(includes non-performers) but the performers currently saved in the
instance ARE correctly highlighted.

This seems like a bug but perhaps I have misunderstood what is
supposed to happen.And is there a workaround?

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-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: limit_choices_to using a dynamic model attribute

2009-03-30 Thread Jamie

Ah, after playing with the code some more I resolved my own problem.
Instead of relying on the 'is_active' dynamic model attribute for use
with limit_choices_to, I was able to get the following to accomplish
the same task:

limit_choices_to={ 'end_date__gte': datetime.date.today,
'start_date__lte': datetime.date.today }




On Mar 30, 1:53 pm, Jamie <utkja...@gmail.com> wrote:
> Is it possible to use limit_choices_to with a dynamic model attribute?
>
> Some background: I am using a StaffMember model for content creators
> who do not have user accounts. Each staff member has a start and end
> date and the model has a dynamic attribute called 'is_active' that
> compares the start/end dates to the current date and returns either
> True or False depending on whether the staff member is active or not.
>
> When creating content, I need to be able to use limit_choices_to to
> limit the drop-down choices to only those staff members that are
> currently active (otherwise we'll have hundreds of inactive alumni
> staff showing up in the list of choices every time we post new
> content). Django returns a "Cannot resolve keyword 'is_active' into
> field" error when I try to do this.
>
> I could add an "is_active" field to the StaffMember model, but that
> would be redundant given the start/end dates and would require admins
> to manually keep track of staff members in a high turn-over
> environment.
>
> On a related note, the dynamic attribute works with list_display but
> not list_filter in admin.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
-~--~~~~--~~--~--~---



limit_choices_to using a dynamic model attribute

2009-03-30 Thread Jamie

Is it possible to use limit_choices_to with a dynamic model attribute?

Some background: I am using a StaffMember model for content creators
who do not have user accounts. Each staff member has a start and end
date and the model has a dynamic attribute called 'is_active' that
compares the start/end dates to the current date and returns either
True or False depending on whether the staff member is active or not.

When creating content, I need to be able to use limit_choices_to to
limit the drop-down choices to only those staff members that are
currently active (otherwise we'll have hundreds of inactive alumni
staff showing up in the list of choices every time we post new
content). Django returns a "Cannot resolve keyword 'is_active' into
field" error when I try to do this.

I could add an "is_active" field to the StaffMember model, but that
would be redundant given the start/end dates and would require admins
to manually keep track of staff members in a high turn-over
environment.

On a related note, the dynamic attribute works with list_display but
not list_filter in admin.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: How to properly use limit_choices_to on self-joins

2009-03-20 Thread Laran Evans

Bump. Anyone? Is this so easy that nobody's challenged to answer it?
Or is this something weird that I'm doing?

- laran

On Mar 19, 1:20 pm, Laran Evans <laran.ev...@gmail.com> wrote:
> I have a Company class. A Company has many Clients, each of which is
> also a Company. The problem I have is that in the auto-generated Admin
> site, the Clients show up as a multi-select with the Company in the
> select box. This doesn't make sense, because a company can't select
> itself as a client.
>
> So, how do I specify in the model that the company should not show up
> in its list of clients?
>
> I tried to do it by saying the client id should not equal the parent
> company id. But I don't seem to be able to get the syntax right.
>
> Can anyone shed light on this? Thanks.
>
> ---
>
> class Company(models.Model):
>         name                 = models.CharField(max_length=128)
>         main_phone_number    = models.CharField
> (max_length=64,blank=True,null=True)
>         main_email_address   = models.EmailField(blank=True,null=True)
>         url                  = models.URLField(blank=True,null=True)
>         clients              = models.ManyToManyField
> ('self',blank=True,null=True,limit_choices_to={'id__ne':'id'})
>
>         def __unicode__(self):
>                 return u'%s' % self.name
--~--~-~--~~~---~--~~
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 properly use limit_choices_to on self-joins

2009-03-19 Thread Laran Evans

I have a Company class. A Company has many Clients, each of which is
also a Company. The problem I have is that in the auto-generated Admin
site, the Clients show up as a multi-select with the Company in the
select box. This doesn't make sense, because a company can't select
itself as a client.

So, how do I specify in the model that the company should not show up
in its list of clients?

I tried to do it by saying the client id should not equal the parent
company id. But I don't seem to be able to get the syntax right.

Can anyone shed light on this? Thanks.

---

class Company(models.Model):
name = models.CharField(max_length=128)
main_phone_number= models.CharField
(max_length=64,blank=True,null=True)
main_email_address   = models.EmailField(blank=True,null=True)
url  = models.URLField(blank=True,null=True)
clients  = models.ManyToManyField
('self',blank=True,null=True,limit_choices_to={'id__ne':'id'})

def __unicode__(self):
return u'%s' % self.name

--~--~-~--~~~---~--~~
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: referencing the current instance inside limit_choices_to

2008-12-10 Thread bruno desthuilliers

On 10 déc, 19:25, fiedzia <[EMAIL PROTECTED]> wrote:
> On Dec 10, 1:56 am, GuyBowden <[EMAIL PROTECTED]> wrote:
>
> > I'd like to set the limit_choices_to value of a ForeignKey field based
> > on another selection in the current instance.
>
(snip)
>
> other thing to look at is that what is passed to limit_choices_to
> might be a callable,
> but it doesn't receive instance as parameter (and i would like it
> did).

I had a quick look, and it seems that limit_choices_to doesn't accept
a callable (at least in the svn version I use at work, rev 9100 iirc).
It can be a queryset or any object having a add_to_query(sqlquery)
method, but I failed to find any object implementing this protocol in
django itself, nor any documentation.


--~--~-~--~~~---~--~~
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: referencing the current instance inside limit_choices_to

2008-12-10 Thread fiedzia

On Dec 10, 1:56 am, GuyBowden <[EMAIL PROTECTED]> wrote:

> I'd like to set the limit_choices_to value of a ForeignKey field based
> on another selection in the current instance.

Perhaps someone will come with better idea,
but for now to achieve this result i am modifying queryset in form
derived from model:


class SomeEditForm(ModelForm):
class Meta:
model = my_models.MyModel

def __init__(self,  *args,  **kwargs):
self.fields['author'].queryset =
my_models.MyModel.objects.filter(user=self.tied_user)


other thing to look at is that what is passed to limit_choices_to
might be a callable,
but it doesn't receive instance as parameter (and i would like it
did).


--
Maciej "Fiedzia" Dziardziel
--~--~-~--~~~---~--~~
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: referencing the current instance inside limit_choices_to

2008-12-10 Thread GuyBowden

Thankyou - saves me searching down this dead end...

Cheers,

Guy

On Dec 10, 7:54 am, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
> There is no way to have per-instance limit_choices_to.
>
> On Wed, Dec 10, 2008 at 03:56, GuyBowden <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I've looked about but can't find the answer to this.
>
> > I'd like to set the limit_choices_to value of a ForeignKey field based
> > on another selection in the current instance.
>
> > i.e. - filter the choices based on another field of the same instance.
>
> > something like this:
>
> > my_fk.limit_choices_to = my_fk.objects.get(Q(type = self.fk_type))
>
> > but that fails as self is not defined by then obviously...
>
> > 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-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: referencing the current instance inside limit_choices_to

2008-12-09 Thread Alex Koshelev
There is no way to have per-instance limit_choices_to.


On Wed, Dec 10, 2008 at 03:56, GuyBowden <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I've looked about but can't find the answer to this.
>
> I'd like to set the limit_choices_to value of a ForeignKey field based
> on another selection in the current instance.
>
> i.e. - filter the choices based on another field of the same instance.
>
> something like this:
>
> my_fk.limit_choices_to = my_fk.objects.get(Q(type = self.fk_type))
>
> but that fails as self is not defined by then obviously...
>
> 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-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
-~--~~~~--~~--~--~---



referencing the current instance inside limit_choices_to

2008-12-09 Thread GuyBowden

Hi,

I've looked about but can't find the answer to this.

I'd like to set the limit_choices_to value of a ForeignKey field based
on another selection in the current instance.

i.e. - filter the choices based on another field of the same instance.

something like this:

my_fk.limit_choices_to = my_fk.objects.get(Q(type = self.fk_type))

but that fails as self is not defined by then obviously...

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-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: Access the current instance from limit_choices_to?

2008-10-27 Thread Alex Rades

Also discussed here:

http://groups.google.com/group/django-users/browse_thread/thread/51228899c5a9a6c/d49271983401e29e

"If my original post was not entirely clear, I'm interested in any
method available to limit_choices_to that lets you dynamically create
the list of available options as a function of the current model
instance. "

On Mon, Oct 27, 2008 at 1:16 PM, Alex Rades <[EMAIL PROTECTED]> wrote:
> Hi,
>  is there currently a way to have something like:
>
> class Mother(models.Model):
>firstborn = models.ForeignKey('Child',
> limit_choices_to={'mother':lambda me: me})
>
> class Child(models.Model):
>mother = models.ForeignKey('Mother', related_name='children')
>
> (taken from http://code.djangoproject.com/ticket/2445 )
>
> Basically I'd like to have access to the current instance of the
> class, when working with limit_choices_to. Of course we can't use self
> (we're still defining the class).
>
> Thank you!
>

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



Access the current instance from limit_choices_to?

2008-10-27 Thread Alex Rades

Hi,
 is there currently a way to have something like:

class Mother(models.Model):
firstborn = models.ForeignKey('Child',
limit_choices_to={'mother':lambda me: me})

class Child(models.Model):
mother = models.ForeignKey('Mother', related_name='children')

(taken from http://code.djangoproject.com/ticket/2445 )

Basically I'd like to have access to the current instance of the
class, when working with limit_choices_to. Of course we can't use self
(we're still defining the class).

Thank you!

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



dynamic values in limit_choices_to

2008-10-16 Thread yves_s

Hi

I have this 2 models

[CODE]

class FontFamily(models.Model):
name = models.CharField(max_length="50")
default_fontfile = models.ForeignKey('FontFile',
  limit_choices_to =
{ 'id__in' : (1,2) }, # something like 'self.fontfile_set.all()' would
be nice
  blank="True",
  null="True")

class FontFile(models.Model):
name = models.CharField(max_length="50")
path = models.CharField(max_length="100")
font_family = models.ForeignKey(FontFamily)

[/CODE]

I want to use "limit_choices_to" to limit the default_fontfile chooses
in the django admin interface, to only allow the fontfiles which are
associated to the current fontfamily.
In this example I set them to the static values (1,2), but I want them
to be dynamic, callable.

Can this be solved on the module level?
Is there an alternative way for doing this in the admin interface, by
altering the drop-down list before it shows up?

I have found this related ticket:
http://code.djangoproject.com/ticket/2445
in this ticket it seems that the functionality is not currently
implemented in django

I'm using Django 1.0.

any help is very welcome :-)
Yves
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Newbie help with limit_choices_to on ManyToMany

2008-10-06 Thread Lars Stavholm

Hi All,

I'm rather new to django (and python) so I tend to get lost sometimes:

I'm looking to limit the choices in a ManyToMany relationship:

class Computer(models.Model):
host = models.CharField(max_length = 20, unique = True)
def __unicode__(self):
return self.host

class Configuration(models.Model):
name   = models.CharField(max_length = 20, unique = True)
hosts  = models.ManyToManyField(Computer)
def __unicode__(self):
return self.name

admin.py has a "filter_horizontal = ('hosts',)" in the
ConfigurationAdmin class. So, in the admin interface, for each
Configuration I create, I can populate the "Chosen hosts" form
table from the "Available hosts" form table.

So far so good, now I would like the "Available hosts" form table
to show only hosts that's not part in *any* previous Configuration,
i.e. when I've used up all hosts, the "Available hosts" form table
should be empty. What's the best way to solve this? By using
limit_choices_to somehow I guess.

Any ideas appreciated
/Lars


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



using limit_choices_to in foreignKey

2008-06-26 Thread mariu

hello,  have the following problem with limit_choices_to:

class Actividad(models.Model):
nombre=CharField(max_length=50,core=True)
Tipo_Anexo=ForeignKey('Tipo_Anexo',edit_inline=models.TABULAR)

class Anexo_Contrato(models.Model):
nombre=CharField(max_length=50)
Tipo_Anexo=ForeignKey('Tipo_Anexo',verbose_name='Tipo de Anexo')

 class Anexo_CronogramaEjecucion(models.Model):
Anexo=ForeignKey('Anexo_Contrato',edit_inline=models.TABULAR)
 
Actividad=ForeignKey('Actividad',core=True,limit_choices_to={'Tipo_Anexo':Anexo.Tipo_Anexo})

in this way the error gives me: object has no atribute 'Tipo_Anexo'.

however if I fix the value to him he makes out trouble-free Tipo_Anexo:
2
Actividad=ForeignKey('Actividad',core=True,limit_choices_to={'Tipo_Anexo':
2})

please I am new in Django, any sujerenciases himself them agradecere..
 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-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: help - limit_choices_to

2008-06-22 Thread M.Ganesh

Karen Tracey wrote:
> On Sat, Jun 21, 2008 at 9:23 PM, M.Ganesh <[EMAIL PROTECTED] 
> > wrote:
>
>
> Hi All,
>
> This question might have been answered so may times, but I am
> unable to
> glean the information I am looking for from the 260 odd entries that
> turn up while searching the mailing-list archives. So here I ask again
>
> #my models
> class entity(models.Model):
>name = models.Charfield()
>
> class address(models.Model):
>entity = models.FK(entity)
>  #entites can
> have multiple addresses
>street_address = models.TextField(...)
>
> class despatch(models.Model):
>sent_to = models.FK(entity, related_name = 'receiver')
>address = models.FK(address)
>sent_by = models.FK(entity, related_name = 'sender')
>
> Now when I show a form to enter 'despatch' data, after the user
> selects
> the sent_to 'sent_to' address, I want to show only the addresses
> of that
> entity in the 'address' selection. How do I do it?
>
> Note : I don't know java scripts, AJAX etc yet. If the above can be
> achieved only using  these,  then a  small  code snippet  will
>  help me
> start
>
>
> I have not had to do this myself, so have no code snippet to share.  
> It does seem like a commonly-discussed thing, but in a quick Google 
> search I didn't find anything that matched exactly.  This page:
>
> http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/
>
> discusses doing exactly what you want with jQuery and Ajax...and PHP.  
> So not quite what you are looking for.  But this page:
>
> http://www.packtpub.com/article/enhancing-the-user-interface-with-ajax
>
> discusses adding jQuery to a Django app and doing other cool stuff 
> with it. So probably you can glean bits of information from both and 
> put it together to do what you are looking for.  I do believe you need 
> to learn a little Javascript/Ajax to do this.
>
> Karen
Thanks Karen for the leads. I'll follow those breadcrumbs

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: help - limit_choices_to

2008-06-21 Thread Karen Tracey
On Sat, Jun 21, 2008 at 9:23 PM, M.Ganesh <[EMAIL PROTECTED]> wrote:

>
> Hi All,
>
> This question might have been answered so may times, but I am unable to
> glean the information I am looking for from the 260 odd entries that
> turn up while searching the mailing-list archives. So here I ask again
>
> #my models
> class entity(models.Model):
>name = models.Charfield()
>
> class address(models.Model):
>entity = models.FK(entity)  #entites can
> have multiple addresses
>street_address = models.TextField(...)
>
> class despatch(models.Model):
>sent_to = models.FK(entity, related_name = 'receiver')
>address = models.FK(address)
>sent_by = models.FK(entity, related_name = 'sender')
>
> Now when I show a form to enter 'despatch' data, after the user selects
> the sent_to 'sent_to' address, I want to show only the addresses of that
> entity in the 'address' selection. How do I do it?
>
> Note : I don't know java scripts, AJAX etc yet. If the above can be
> achieved only using  these,  then a  small  code snippet  will  help me
> start
>

I have not had to do this myself, so have no code snippet to share.  It does
seem like a commonly-discussed thing, but in a quick Google search I didn't
find anything that matched exactly.  This page:

http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/

discusses doing exactly what you want with jQuery and Ajax...and PHP.  So
not quite what you are looking for.  But this page:

http://www.packtpub.com/article/enhancing-the-user-interface-with-ajax

discusses adding jQuery to a Django app and doing other cool stuff with it.
So probably you can glean bits of information from both and put it together
to do what you are looking for.  I do believe you need to learn a little
Javascript/Ajax to do this.

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



help - limit_choices_to

2008-06-21 Thread M.Ganesh

Hi All,

This question might have been answered so may times, but I am unable to 
glean the information I am looking for from the 260 odd entries that 
turn up while searching the mailing-list archives. So here I ask again

#my models
class entity(models.Model):
name = models.Charfield()
  
class address(models.Model):
entity = models.FK(entity)  #entites can 
have multiple addresses
street_address = models.TextField(...)

class despatch(models.Model):
sent_to = models.FK(entity, related_name = 'receiver')
address = models.FK(address)
sent_by = models.FK(entity, related_name = 'sender')

Now when I show a form to enter 'despatch' data, after the user selects 
the sent_to 'sent_to' address, I want to show only the addresses of that 
entity in the 'address' selection. How do I do it?

Note : I don't know java scripts, AJAX etc yet. If the above can be 
achieved only using  these,  then a  small  code snippet  will  help me 
start

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



help with limit_choices_to

2008-05-08 Thread Matias Surdi

Hi.

I've the following model:

class ExamAttributeCalification(models.Model):
exam_result = models.ForeignKey(ExamResult, 
edit_inline=models.TABULAR, num_in_admin=1)
exam_attribute = 
models.ForeignKey(ExamAttribute,limit_choices_to={"exam__id":1})
 calification = models.IntegerField(core=True)


As you can see, in the last line I've a hardcoded "1". This id should be 
taken dynamically from exam_result.exam.id model attribute.

How could I accomplish this?

Thanks 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-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: limit_choices_to in ModelForm

2008-01-19 Thread James Bennett

On Jan 19, 2008 3:51 AM, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote:
> I have a limit_choices_to in my model - but this does work on my
> ModelForm. How do I do this?

Either set up the ModelChoiceField manually and specify the QuerySet,
or hang on while I get around to adding tests to the patch on #4046
(which I'd forgotten about in the middle of a bunch of other stuff).

http://code.djangoproject.com/ticket/4046

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



limit_choices_to in ModelForm

2008-01-19 Thread Kenneth Gonsalves

hi,
I have a limit_choices_to in my model - but this does work on my  
ModelForm. How do I do this?
-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/
Foss Conference for the common man: http://registration.fossconf.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-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
-~--~~~~--~~--~--~---



newadmin: where is 'limit_choices_to'

2007-12-17 Thread René Schneider

Hello
I am a newbe on this list. With the oldforms-admin i made a model with 
some fields with 'limit_choices_to' options. Then i tried it with the 
newadmin. There is no error message but also no effect. The list is not 
'limited' but 'full'. Is this option gone in newadmin or have i to 
program it in another way?
Thanks for your answer
René


--~--~-~--~~~---~--~~
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: complex query in limit_choices_to

2007-11-24 Thread leotr

On database level that should be done by UNIQUE constraints.
And your problem should be made on form level.
read about ChoiceField in newforms documentation
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



complex query in limit_choices_to

2007-11-23 Thread Kenneth Gonsalves

hi,

I have two models called Child and Sponsor. There is a model called  
Sponsorship which has foreign keys to Child and Sponsor. For the  
foreign key to Child, I want to limit choices to all those children  
who are *not* already a foreign key to sponsorship and who are  
active. This is the query I generate to get this list:

Child.objects.extra(
where=["""id not in(select child_id from web_sponsorship\
where web_sponsorship.iscurrent=True)"""]
).filter(iscurrent=True)

how do i get this into the limit_choices_to dictionary?

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/
Foss Conference for the common man: http://registration.fossconf.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-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
-~--~~~~--~~--~--~---



self referencing limit_choices_to

2007-11-05 Thread Brot

Hello,

I have a little problem with the "limit_choices_to" functionality. I
found two group discussions concerning the same problem, but the
authors got no answers.
http://groups.google.com/group/django-users/browse_thread/thread/fab619f35e322486/e9f34786dbba2666?lnk=gst=limit_choices_to#e9f34786dbba2666
http://groups.google.com/group/django-users/browse_thread/thread/881f29143ec8a6e/ffe217c861e090f2?lnk=gst=limit_choices_to#ffe217c861e090f2

--
class EventType(models.Model):
desc = models.CharField(max_length=40, unique=True)
valid_from = models.DateField()
valid_to = models.DateField()
.

class Event(models.Model):
date = models.DateField(core=True)
type = models.ForeignKey(EventType, limit_choices_to =
 
{'valid_from__lte': ?
 
'valid_to__gte': ?})

 = should be the value Event.date
---
errormessage if I type: self.date

type = models.ForeignKey(EventType, limit_choices_to =
{'valid_from__lte': self.date})
NameError: name 'self' is not defined
---
errormessage if I type: date

Incorrect date value: '' for column 'valid_from' at row 1
---


I hope that someone will help me!

Regards
  Bernd


--~--~-~--~~~---~--~~
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: limit_choices_to has no effect on list_filter?

2007-09-02 Thread patrickk

I already found a patch from 25.2.2007.
Don´t know why it´s not in the trunk yet, but it seems to work.

Patrick

On 2 Sep., 21:27, patrickk <[EMAIL PROTECTED]> wrote:
> I thought this has been working, but I´m not sure:
>
> content_type = models.ForeignKey(ContentType, limit_choices_to =
> {'pk__in': [10, 24, 25, 26, 51]})
> ...
> list_filter = ('createdate', 'updatedate', 'category',
> 'content_type',)
>
> in the filter, alle the content_types show up, although I´ve been
> limiting them with limit_choices_to.
>
> Any suggestions?
>
> Thanks,
> Patrick


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



limit_choices_to has no effect on list_filter?

2007-09-02 Thread patrickk

I thought this has been working, but I´m not sure:

content_type = models.ForeignKey(ContentType, limit_choices_to =
{'pk__in': [10, 24, 25, 26, 51]})
...
list_filter = ('createdate', 'updatedate', 'category',
'content_type',)

in the filter, alle the content_types show up, although I´ve been
limiting them with limit_choices_to.

Any suggestions?

Thanks,
Patrick


--~--~-~--~~~---~--~~
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: Using limit_choices_to on a ManyToMany Field

2007-08-02 Thread Russell Keith-Magee

On 8/3/07, Greg <[EMAIL PROTECTED]> wrote:
>
> Come onI know that somebody can figure this out

Greg - seriously, it's been 6 hours since your original message. Give
people a chance to _read_ your message before you complain about the
fact that nobody has answered.

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: Using limit_choices_to on a ManyToMany Field

2007-08-02 Thread Greg

Come onI know that somebody can figure this out

sandp = models.ManyToManyField(Choice, limit_choices_to =
{'choice__id': self.collection.id})

What do I need to get the collection id?  Will 'self.collection.id'
work?

I forgot to add my collection class.  Here it is:

class Collection(models.Model):
name = models.CharField(maxlength=200)
collectionslug = models.SlugField(prepopulate_from=["name"])
description = models.TextField(maxlength=1000)
manufacturer = models.ForeignKey(Manufacturer)


Thanks for your help



On Aug 2, 1:23 pm, Greg <[EMAIL PROTECTED]> wrote:
> I've looked everywhere for information on how to use the
> 'limit_choices_to' attribute...but can't seem to find the answer.
>
> I have the following models:
>
> class Choice(models.Model):
> choice = models.ForeignKey(Collection, edit_inline=models.TABULAR,
> num_in_admin=5)
> size = models.ForeignKey(Size, core=True)
> price = models.ForeignKey(Price, core=True)
>
> def __str__(self,):
> return str((self.size, self.price))
>
> class Style(models.Model):
> name = models.CharField(maxlength=200, core=True)
> color = models.CharField(maxlength=100)
> image = models.ImageField(upload_to='site_media/')
> theslug = models.SlugField(prepopulate_from=('name',))
> manufacturer = models.ForeignKey(Manufacturer)
> sandp = models.ManyToManyField(Choice, limit_choices_to =
> {'choice__id': self.collection.id})
> collection = models.ForeignKey(Collection,
> edit_inline=models.TABULAR, num_in_admin=6)
>
> def __str__(self,):
> return self.name
>
> //
>
> Notice my sandp field in my Style class.  We'll it contains the
> limit_choices_to attribute.  Everything works fine When I have:
>
> sandp = models.ManyToManyField(Choice, limit_choices_to =
> {'choice__id': 2})
>
> It returns only the rows that contain 2 in the choice_id field
>
> /
>
> However, I need that '2' to do be dynamic.  I'm not sure how to do
> this.  I tried 'self.collection.id' but that does not work.  I need to
> be able to get what ever the id is for the collection that the style
> is tied to.
>
> //
>
> I've looked at all the documentation and I can't seem to find the
> answer.  Any help would GREATLY be appreciated.
>
> 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Using limit_choices_to on a ManyToMany Field

2007-08-02 Thread Greg

I've looked everywhere for information on how to use the
'limit_choices_to' attribute...but can't seem to find the answer.

I have the following models:

class Choice(models.Model):
choice = models.ForeignKey(Collection, edit_inline=models.TABULAR,
num_in_admin=5)
size = models.ForeignKey(Size, core=True)
price = models.ForeignKey(Price, core=True)

def __str__(self,):
return str((self.size, self.price))

class Style(models.Model):
name = models.CharField(maxlength=200, core=True)
color = models.CharField(maxlength=100)
image = models.ImageField(upload_to='site_media/')
theslug = models.SlugField(prepopulate_from=('name',))
manufacturer = models.ForeignKey(Manufacturer)
sandp = models.ManyToManyField(Choice, limit_choices_to =
{'choice__id': self.collection.id})
collection = models.ForeignKey(Collection,
edit_inline=models.TABULAR, num_in_admin=6)

def __str__(self,):
return self.name

//

Notice my sandp field in my Style class.  We'll it contains the
limit_choices_to attribute.  Everything works fine When I have:

sandp = models.ManyToManyField(Choice, limit_choices_to =
{'choice__id': 2})

It returns only the rows that contain 2 in the choice_id field

/

However, I need that '2' to do be dynamic.  I'm not sure how to do
this.  I tried 'self.collection.id' but that does not work.  I need to
be able to get what ever the id is for the collection that the style
is tied to.

//

I've looked at all the documentation and I can't seem to find the
answer.  Any help would GREATLY be appreciated.

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



form_for_model and limit_choices_to

2007-07-15 Thread Birkin James Diana

I've created a newforms form using form_for_model(). The problem I'm  
having is that two fields are not respecting part of the field  
definition in the model; I'm hoping I'm overlooking something.

The end result I want is for a scanner select-menu to show only  
scanners, and a camera select-menu to show only cameras.

In my model (for an 'Item' being digitized), I've defined a scanner  
field as:

scanner = models.ForeignKey(Equipment, null=True, blank=True,  
limit_choices_to={'equipment_type__exact':'scan'},  
related_name='scanner_set')

...and a camera field as:

camera = models.ForeignKey(Equipment, null=True, blank=True,  
limit_choices_to={'equipment_type__exact':'camr'},  
related_name='camera_set')

In the admin, the (beautiful) form that is generated respects this  
definition perfectly: i.e. the scanner select-menu only shows  
equipment entries that are scanners.

However, the scanner and camera select-menus generated by  
{{form_reference.as_table}} in the template show all the 'Equipment'  
entries, ignoring that 'limit-choices_to' model-constraint.

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



complicated limit_choices_to on an inline-edited page

2007-07-12 Thread Charles Wesley

I have a ForeignKey field with the option:

limit_choices_to = {'team__id':
Game.objects.get(pk=1).visitor_team.id}

This class is coded to be edited inline by another class. When I use
the limit_choices_to option above, I can access the class directly,
but not through the other class. When I change the limit_choices_to to
something more basic, like

limit_choices_to = {'team__id': 1}

then I can edit the class inline again.

How can I keep the inline-edited behavior and the complicated
limit_choices_to? Is this a bug in Django?


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



limit_choices_to confusion

2007-05-30 Thread Todd O'Bryan

I was trying to use limit_choices_to in what I thought was an intuitive
way.

class Organization(models.Model):
members = ManyToManyField(User)

class Committee(models.Model):
org = ForeignKey(Organization)
chair = ForeignKey(
User,
limit_choices_to={ 'organization_set__contains' : org })

What I want to do is limit the choices for the chair to only people who
are members of the organization. (What I realize now is that the
CONTAINS clause appears in the actual SQL WHERE clause and is trying to
do a text match, so I see why it doesn't work.)

Is there an easy and natural way to do this with the database API?

Thanks,
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-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: Help with limit_choices_to

2007-05-15 Thread xgdlm

> At the moment, the easiest way I see to to that is to include a JS
> file that will catch the current member_id, then call an external page
> that will return a JSON string  of
> "Folder.objects.filter(member=member) " query_set and then build the
> wished multiselected box .. I'll try that way :p
>

FYI I did implement this limit choice to with ajax and javascript and
this is working well.

Item Folder Many-to-Many relationship is now define as (wich shown
coma separated id if no JS)

Folder = models.ManyToManyField(Folder,raw_id_admin=True,blank=True)

then I use a JS file and 2 ajax request to rebuild a multiselect
box :)

xav


--~--~-~--~~~---~--~~
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: Help with limit_choices_to

2007-05-14 Thread xgdlm

Hello

Thank you Malcolm for your fast answer (as usual)


> However, you
> cannot pass parameters to that function: it's mostly for use with things
> like datetime.datetime.now -- where the result of the function does not
> depend on "self" in any fashion.

Hum, that what I understood, but now I have confirmation :/  So there
is no way to use standard admin edit item page to to that.
At the moment, the easiest way I see to to that is to include a JS
file that will catch the current member_id, then call an external page
that will return a JSON string  of
"Folder.objects.filter(member=member) " query_set and then build the
wished multiselected box .. I'll try that way :p

Thanks again

xav


--~--~-~--~~~---~--~~
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: Help with limit_choices_to

2007-05-14 Thread Malcolm Tredinnick

On Mon, 2007-05-14 at 08:45 +, xgdlm wrote:
> Hello all !
> 
> I have trouble using limit_choices_to on the following modele. I
> searched the group and googled but I couldn't find the solution.
> 
> Here is my modeles :
> -
> class Member(models.Model):
>   login = models.CharField(maxlength=50,unique=True, db_index=True,
> null=False)
>   password = models.CharField(maxlength=250, null=False, db_index=True)
> 
> class Folder(models.Model):
>   member = models.ForeignKey(Member,raw_id_admin=True,db_index=True)
>   name = models.CharField(maxlength=100,null=False)
>   created_at = models.DateTimeField(null=False,db_index=True)
> 
> class Item(models.Model):
>   member = models.ForeignKey(Member,raw_id_admin=True,db_index=True)
>   Folder =
> models.ManyToManyField(Folder,filter_interface=models.HORIZONTAL,symmetrical=True,
> db_index=True)
>   created_at = models.DateTimeField(null=False,db_index=True)
>   updated_at = models.DateTimeField(null=False,db_index=True)
> 
> -
> 
> I wish, in the admin interface, to use  limit_choices_to on the Item
> model to limit the list of folders shown for an item.
> In other words, when editing an item I would like that only the
> folders owned by the item member are shown :
> 
> limit_choices_to={'id__in':member.folder_set.all()} but this doesn't
> work.

You cannot do this with limit_choices_to. The arguments are not
evaluated at call time, only at import time.
 
> 
> I also try to add a function like:
> 
> def testing(member):
>   return Folder.objects.filter(member=member)
> 
> and
> 
> limit_choices_to={'id__in': testing(member)}
> 
> but this doesn't do the trick,

This is exactly the same as your first attempt, because you are putting
the result of the function call in the dictionary. The documentation
says you can put a callable object (a function or class with a __call__
member) in there and it will be called at evaluation time. However, you
cannot pass parameters to that function: it's mostly for use with things
like datetime.datetime.now -- where the result of the function does not
depend on "self" in any fashion.

Regards,
Malcolm



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



Help with limit_choices_to

2007-05-14 Thread xgdlm

Hello all !

I have trouble using limit_choices_to on the following modele. I
searched the group and googled but I couldn't find the solution.

Here is my modeles :
-
class Member(models.Model):
login = models.CharField(maxlength=50,unique=True, db_index=True,
null=False)
password = models.CharField(maxlength=250, null=False, db_index=True)

class Folder(models.Model):
member = models.ForeignKey(Member,raw_id_admin=True,db_index=True)
name = models.CharField(maxlength=100,null=False)
created_at = models.DateTimeField(null=False,db_index=True)

class Item(models.Model):
member = models.ForeignKey(Member,raw_id_admin=True,db_index=True)
Folder =
models.ManyToManyField(Folder,filter_interface=models.HORIZONTAL,symmetrical=True,
db_index=True)
created_at = models.DateTimeField(null=False,db_index=True)
updated_at = models.DateTimeField(null=False,db_index=True)

-

I wish, in the admin interface, to use  limit_choices_to on the Item
model to limit the list of folders shown for an item.
In other words, when editing an item I would like that only the
folders owned by the item member are shown :

limit_choices_to={'id__in':member.folder_set.all()} but this doesn't
work.

I also try to add a function like:

def testing(member):
return Folder.objects.filter(member=member)

and

limit_choices_to={'id__in': testing(member)}

but this doesn't do the trick,

Does anyone has some ideas how to complete this ?

Thanks in advance,

xav


--~--~-~--~~~---~--~~
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: ManyToManyField, limit_choices_to and properties of the request object

2007-03-19 Thread quentinsf

Brilliant - thanks, Sam.

Is this in the docs anywhere, I wonder?  I've seen a few queries along
these lines.
Might be an FAQ

Q


--~--~-~--~~~---~--~~
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: ManyToManyField, limit_choices_to and properties of the request object

2007-03-19 Thread Sam Morris

On Mon, 19 Mar 2007 09:29:08 -0700, quentinsf wrote:
> I need to do something similar.  In a form I want to limit the options
> in a ForeignKey's pull-down select field to objects owned by an
> organisation of which the user is a member.
> 
> I've been trying to work out where this would fit.  Any help much
> appreciated.

It turns out that you can just set the field's choices after the
manipulator has been created:

 m = Post.AddManipulator ()
 m['images'].choices = [(i.id, i) for i in Image.objects.filter (author = 
request.user)]

-- 
Sam Morris
http://robots.org.uk/

PGP key id 1024D/5EA01078
3412 EA18 1277 354B 991B  C869 B219 7FDB 5EA0 1078


--~--~-~--~~~---~--~~
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: ManyToManyField, limit_choices_to and properties of the request object

2007-03-19 Thread quentinsf

I need to do something similar.  In a form I want to limit the options
in a ForeignKey's pull-down select field to objects owned by an
organisation of which the user is a member.

I've been trying to work out where this would fit.  Any help much
appreciated.



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



ManyToManyField, limit_choices_to and properties of the request object

2007-03-19 Thread Sam Morris
Is it possible to use a ManyToManyField's limit_choices_to attribute to
limit a user to picking only from related objects that have author =
request.user?

Given that request has no place in the model definition, would it be
necessary to write a custom manipulator?

-- 
Sam Morris
http://robots.org.uk/

PGP key id 1024D/5EA01078
3412 EA18 1277 354B 991B  C869 B219 7FDB 5EA0 1078


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


Re: correct limit_choices_to syntax

2007-02-14 Thread Benedict Verheyen

Benedict Verheyen schreef:


I now defined the fields in my custom change manipulator:
self.fields = (
 forms.PositiveIntegerField(field_name="Admissionnr", is_required=True),
 ...
 forms.SelectField(field_name="kamer", choices=room_choices),
 ...
)

This displays the correct list of available beds but it doesn't select
the bed of the patient when you edit the patient info like it normally
does with foreign keys. The selection is empty

Why is that?

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-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: correct limit_choices_to syntax

2007-02-13 Thread Benedict Verheyen

ScottB schreef:
> I think you need to pass the actual values (i.e. the rooms), rather
> than a function that returns them.  Also 'id_in' needs two
> underscores.  So maybe:
> 
> limit_choices_to = {'id__in': get_rooms()}
> 
> Scott

Indeed, i had already found out there was an underscore short.
I tried 'id__in': get_rooms() and that won't work as it doesn't know
Patient when the function is called. That's why you have to use
get_rooms instead of get_rooms. The error is "global name 'Patient' is
not defined".

So it seems like this method is not going to work after all.
Are there any other ways to get a limited list (keeping in mind i'm not
using newforms) for a ForeignKey field?

I tried using this in my view:
room_choices = [(room.id, str(room)) for room in Room.objects.filter() ]
room_choices.sort()
room_choices.insert(0,BLANK_CHOICE_DASH[0]) # [('','-')]

Since i don't want to redesign the whole form, i change the current
field entry. I first look up the index of the field:
index = 0
for field in fields:
if ( field.field_name == "room" ): break
index+=1
return index

Then i replace that index with my version:
fields[index] = forms.SelectField(field_name="room", choices = room_choices)

Which indeed gives me a limited list but when you change the data of a
patient, the room he's in isn't selected. This something i still need to
change as the query leaves out the room/bed of the currently selected
patient too.
But even when i just select all rooms, the room the patient is in isn't
selected. Any idea how you can "select" a choice in the formfield?

Or any less cumbersome method to limit the choices?

Thanks,
Benedict


--~--~-~--~~~---~--~~
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: correct limit_choices_to syntax

2007-02-13 Thread ScottB

On Feb 13, 8:06 am, Benedict Verheyen <[EMAIL PROTECTED]>
wrote:
> def get_rooms():
> return Room.objects.exclude(id__in=[patient.room.id for patient in
> Patient.objects.filter(room__isnull=False)])

> I tried limit_choices_to = {'id_in': get_rooms} but this gives me:
> TypeError at /patient/aanpassen/94/
> Cannot resolve keyword 'id_in' into field
>
> limit_choices_to = {'id': get_rooms}
>
> So how can i specify my limited choices?

I think you need to pass the actual values (i.e. the rooms), rather
than a function that returns them.  Also 'id_in' needs two
underscores.  So maybe:

limit_choices_to = {'id__in': get_rooms()}

Scott


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



correct limit_choices_to syntax

2007-02-13 Thread Benedict Verheyen

Hi,

i'm trying to limit what the user sees for a certain Foreign key.
I was told to use the limited_choices_to argument and it indeed seems
to fit the bill. However, i'm doing something wrong as this is what i get:

TypeError at /patient/edit/94/
_filter_or_exclude() argument after ** must be a dictionary

This is the relevant code from my models.py
def get_rooms():
return Room.objects.exclude(id__in=[patient.room.id for patient in
Patient.objects.filter(room__isnull=False)])

class Patient(models.Model):
room = models.ForeignKey(Room, blank=True, null=True,
limit_choices_to = get_rooms )

I tried limit_choices_to = {'id_in': get_rooms} but this gives me:
TypeError at /patient/aanpassen/94/
Cannot resolve keyword 'id_in' into field

limit_choices_to = {'id': get_rooms}

So how can i specify my limited choices?

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-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: limit_choices_to: getting access to current instance

2007-01-31 Thread qhfgva

Well, either I'm not able to follow your example or we are talking
about different things.  In any case here is what I got working as a
first draft.  As a big benefit to me is the fact that I now understand
these inner workings a little better.  I was hoping to get away with
simple wrappers to generic views but now I don't think that will be
the case but it also doesn't worry me.  :)

This is closely adapted from:  http://code.pui.ch/2007/01/07/using-
djangos-newforms/

from django import newforms as forms
from django.newforms import widgets
from django.template import loader, Context
from django.http import HttpResponse

def create_update_animal(request, animal_id=None):
animal = None
if animal_id:
animal = Animal.objects.get(id=animal_id)
animal_form = forms.models.form_for_instance(animal)
else:
animal_form = forms.models.form_for_model(Animal)

if animal:
available_protocols = Protocol.allowed_for_animal(animal)
else:
available_protocols = Protocol.active_list()

protocol_choices = [('','')] + [(p.id,p.number) for p in
available_protocols]
animal_form.base_fields['protocol'].widget.choices =
protocol_choices
if animal:
animal_form.base_fields['protocol'].widget.initial =
animal.protocol_id

if request.method == 'POST':
form = animal_form(request.POST)

if form.is_valid():
form.save()
return HttpResponseRedirect("/")
else:
form = animal_form()
t = loader.get_template('tracker/animal_form.html')

c = Context({ 'form': form, })

return HttpResponse(t.render(c))


If there is a way to do the above just using limit_choices_to, I'd
still like to understand that method.  Also if I'm doing anything
particularly hacky feel free to mock me (but also instruct me as to a
better way).

thanks.


On Jan 30, 5:04 pm, "quentinsf" <[EMAIL PROTECTED]> wrote:
> Sorry, the reference to 'Display' should have been to 'MyObject'


--~--~-~--~~~---~--~~
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: limit_choices_to: getting access to current instance

2007-01-30 Thread quentinsf

I'm not quite sure if this is helpful - it's not a general solution on 
the ForeignKey specification so wouldn't work in admin, for example, 
but it worked for me with my own form...

I was creating a view for a 'change' form.  One parameter passed to 
the view (from the URL) was an organisation identifier.I wanted to 
restrict the choices in a ForeignKey form field to those which were 
relevant to that organisation.  This seemed to work:

 def myobject_edit(request, org_id, obj_id):
 org = get_object_or_404(Organisation, pk=org_id)
 manip = Display.ChangeManipulator(obj_id)
 manip['otherobj'].choices = [
 (e['id'], e['name']) for e in 
OtherObj.objects.filter(org__exact=org).values()
 ]
 ...


--~--~-~--~~~---~--~~
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: limit_choices_to: getting access to current instance

2007-01-30 Thread [EMAIL PROTECTED]

As far as I understand, you could certainly implement the same 
functionality in a view using newforms to validate the input. To do it 
in the model, something like the patch suggested in the ticket or the 
approach linked to at the end of the comments on that ticket would be 
needed. The code here shows the crucial ingredient:

def get_limit_choices_to(self):
limiters = {}
if self.limit_choices_to:
for id in self.limit_choices_to:
value = self.limit_choices_to[id]
if callable(value):
value = value()
limiters[id] = value
return limiters

The check for whether limit_choices_to is a callable() is what you 
need: the ability to have limit_choices_to evaluated at runtime rather 
than just an array stuck into the model that is checked against. If 
you look into the Django model API documentation example that uses 
models.LazyDate() and do some hunting around code.djangoproject.com 
for discussion about LazyDate, you'll see that people have done some 
pretty odd things to delay the checking of limit_choices_to until the 
model class is actually instantiated.

IN SHORT: ;-) the get_assigned_tasks_id_list(blah, blah) is just a 
stand in for whatever code you might want to run when the model is 
instantiated to check what should allowed as input.

On Jan 29, 1:57 pm, "qhfgva" <[EMAIL PROTECTED]> wrote:
> Thanks for the response.  I'm not sure if this exactly covers my case
> but I like this feature.  From the example given in the ticket:
>
> def assigned_tasks():
>return get_assigned_tasks_id_list(blah, blah)
>
> class TimeRecord(models.Model):
>task = models.ForeignKey(Task, limit_choices_to = {'id__in':
> assigned_tasks})
>
> I would like the assigned_tasks function to be have a reference to and
> be able to calculate values based on the current instance of
> TimeRecord.Perhaps that is what blah or blah are but I'm guessing
> not.
>
> Do I need to do something like work directly with newforms to achieve
> something like this?
>
> On Jan 29, 6:54 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > See patch on ticket <http://code.djangoproject.com/ticket/2445>.
>
> > On Jan 29, 8:31 am, "qhfgva" <[EMAIL PROTECTED]> wrote:
>
> > > If my original post was not entirely clear, I'm interested in any
> > > method available to limit_choices_to that lets you dynamically create
> > > the list of available options as a function of the current model
> > > instance.
>
> > > thanks.
>
> > > On Jan 28, 4:28 pm, "qhfgva" <[EMAIL PROTECTED]> wrote:
>
> > > > I currently have a drop down for a model where I'd only like to show
> > > > choices that are currently "active".  That's easy enough with:
>
> > > > foo  = models.ForeignKey(Foo,
> > > > limit_choices_to={'active__exact':True})
>
> > > > But if someone is working with a model where the "foo" that they had
> > > > previously selected has been subsequently set to inactive they should
> > > > be able to keep that foo (they are "grandfathered" in).
>
> > > > In effect I'd like limit_choices_to to have a list of foo.active ==
> > > > True plus the current selection they have from the past if it is not
> > > > an active choice.
>
> > > > If I could make a method of Foo such as Foo.allowed_choice_for_x  and
> > > > then pass it an instance of the current object, then it seems like I
> > > > could easily generate the specific drop downlist on the fly but I'm
> > > > not sure how to do that (or if it's possible).
>
> > > > Thoughts?


--~--~-~--~~~---~--~~
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: limit_choices_to: getting access to current instance

2007-01-29 Thread qhfgva

Thanks for the response.  I'm not sure if this exactly covers my case 
but I like this feature.  From the example given in the ticket:

def assigned_tasks():
   return get_assigned_tasks_id_list(blah, blah)

class TimeRecord(models.Model):
   task = models.ForeignKey(Task, limit_choices_to = {'id__in': 
assigned_tasks})


I would like the assigned_tasks function to be have a reference to and 
be able to calculate values based on the current instance of 
TimeRecord.Perhaps that is what blah or blah are but I'm guessing 
not.

Do I need to do something like work directly with newforms to achieve 
something like this?

On Jan 29, 6:54 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> 
wrote:
> See patch on ticket <http://code.djangoproject.com/ticket/2445>.
>
> On Jan 29, 8:31 am, "qhfgva" <[EMAIL PROTECTED]> wrote:
>
> > If my original post was not entirely clear, I'm interested in any
> > method available to limit_choices_to that lets you dynamically create
> > the list of available options as a function of the current model
> > instance.
>
> > thanks.
>
> > On Jan 28, 4:28 pm, "qhfgva" <[EMAIL PROTECTED]> wrote:
>
> > > I currently have a drop down for a model where I'd only like to show
> > > choices that are currently "active".  That's easy enough with:
>
> > > foo  = models.ForeignKey(Foo,
> > > limit_choices_to={'active__exact':True})
>
> > > But if someone is working with a model where the "foo" that they had
> > > previously selected has been subsequently set to inactive they should
> > > be able to keep that foo (they are "grandfathered" in).
>
> > > In effect I'd like limit_choices_to to have a list of foo.active ==
> > > True plus the current selection they have from the past if it is not
> > > an active choice.
>
> > > If I could make a method of Foo such as Foo.allowed_choice_for_x  and
> > > then pass it an instance of the current object, then it seems like I
> > > could easily generate the specific drop downlist on the fly but I'm
> > > not sure how to do that (or if it's possible).
>
> > > Thoughts?


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



  1   2   >