Re: how to do a django data migration on a massive Postgres data table (solved)

2015-05-26 Thread aRkadeFR

Thanks for the email on the django-user ML.

I don't see the gist though, is the problem from me?

On 05/22/2015 09:09 PM, Vernon D. Cole wrote:
Django migrations are run in a single transaction (if your database is 
capable of doing a rollback of DDL, as PostgreSQL is) so data 
migrations of large tables become impossible.


I was able to solve this problem by having the migration run a no-wait 
subprocess which performs the data migration using raw SQL without the 
django ORM.  In order to keep things together, the subprocess is 
contained in the same source file as the migration... when run as a 
module it runs itself as a main program.  In my case, it ran for about 
two days, converting my 10 million row table 1000 rows at a time. 
[Actually, I had to restart it three times by pretending to remove it 
and then re-applying it.]


In case I need to do it some other time, I am putting the code into a 
GIST.  I am posting here so that others may find it when searching for 
the right keywords...

https://gist.github.com/9adedbab1899224a4eaf.git

--
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/86fda457-03a2-4ef7-9d3f-e540fa0e8c1d%40googlegroups.com 
.

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


--
aRkadeFR

--
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/55644FCD.5090002%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: Avoiding Keyboard Input for Removing Stale Content Types Automatically (migrations and automatic deployment)

2015-05-26 Thread Greg Shikhman
Thanks for documenting your trouble, I ran into the same problem today. The 
kludge solution that I came up with was: 'yes yes | python manage.py 
migrate' in my deployment script -- decidedly suboptimal.

My preference would be for the yes/no decision of dropping stale models to 
be recorded within the migration itself at creation time, analogous to the 
choice of a backfill value a new column without a default value on existing 
rows. 

On Wednesday, May 20, 2015 at 10:22:45 PM UTC-4, Proto wrote:
>
> I submitted this ticket recently: 
> https://code.djangoproject.com/ticket/24820 
>
> The content of it is as follows:
>
> While removing models in one of my migrations, I was prompted by Django to 
>> input yes/no. For development, this is no problem. For automatic 
>> deployments it is.
>>
>> I want to know if there exists or if it's possible to add functionality 
>> to Django to do this. I've created a modification which works, but also 
>> want to learn if anyone else has solved this problem differently.
>>
>> Modifying the deployment file to include --noinput does not solve this 
>> problem (it basically defaults to no which ultimately doesn't remove the 
>> model).
>>
>> The patch I've created seems to be working just fine. My solution 
>> involves editing the contenttypes to take an additional argument. The 
>> argument can be invoked inside a migration file so that I have full control 
>> over when it's used. You can view the code below.
>>
>> Link to diff for the patch I created: 
>> ​https://github.com/Protosac/django/commit/d98fff8219469a363493e8d8455c7ffb2430d36f
>
>
> The Django core team expressed interest in a solution that would address 
> this problem, but rejected my specific implementation. I wanted to open a 
> discussion to learn how other developers were dealing with this issue. 
>

-- 
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/2c5a9dff-7d2b-4a21-8155-3a16e45a7ef7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django-admin.py Error

2015-05-26 Thread Adailton (Dhelbegor)
This the error: 

ImportError: cannot import name _compare_digest

 
if this is one class, verify the import.


example:

in models.py:

class One(...)
  your code here

and admin.py:

from .models import One




>

-- 
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/094ff594-dc23-4567-8617-6cb8a3e88ce0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Gmail oAUTH application for Django

2015-05-26 Thread Great Avenger Singh
Hello Django-People,

I am writing a Gmail oAuth2 application with Django so  one can login to 
Gmail. (I have Desktop Python script ready with me)  

After doing some Google I am able to find following Tutorial:

http://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/

This explains everything I need but I guess there is some change in Django 
Working system from the time when this tutorial is written, Please correct 
me if I am wrong?

Do I need to create Django Project for Gmail oAUTH or I should make it 
Django app?

-- 
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/86054741-65e6-4422-aad6-d3c9ccbc1cdc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to pass a queryset for each different field Admin Inlines

2015-05-26 Thread Felipe
Pretend to have in the Django admin, 4 forms inlines, Each with a pair of 
fields choices, "Attributes" and "Value Option". We have the first pair, 
which initialize the field one with a value, for example color and other 
field you must have a queryset the choices.





















As you can see I need to filter each pair with their default values, if 
Color should show only white, black and blue.

class ProductAttributeValueForm(forms.ModelForm):
attribute = forms.ModelChoiceField(label=_('Attribute'),
widget=forms.Select(attrs={'disabled': 'True'}),
queryset=ProductAttribute.objects.all(), required=False)


class ProductAttributeValueFormSet(BaseInlineFormSet):


def __init__(self, *args, **kwargs):
super(ProductAttributeValueFormSet, self).__init__(*args, **
kwargs)
# This return initial [{'attribute' initial}, {..}, {..}]
self.initial = [{'attribute': a} for a in obj.category.
attributes.all()]
# Now we need to make a queryset to each field of each form 
inline
self.queryset = [{'value_option' .. }, { .. }]

What I do is initialize each attribute with a value, for example, Color and 
passed a queryset to value_option with their respective values, white, blue 
and black.
I have tried to do this two days ago and I have not accomplished anything, 
not if the solution is on the forms or in any function of admin

-- 
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/bd4344d1-68ec-4e62-82fa-88181294a40f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


datepicker

2015-05-26 Thread sum abiut
Hi,
Is there a way to implement jquery datepicker with Django models. I am
looking at http://jqueryui.com/datepicker/ but i am finding very difficult
to apply it to django models. any help will be very much appreciated.

Cheers

-- 
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/CAPCf-y735T-8%3DNVdePFU7UEmN_9SQmsLj9uWUeCQ%2B-dRUMNYjQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: datepicker

2015-05-26 Thread Peith Vergil
I don't think you do it with models. You do it with form fields. An easy
way is to simply create a regular CharField, render it like usual. Then, on
the front-end, you simply target that specific char field and initialize
the datepicker on it.
On May 27, 2015 01:31, "sum abiut"  wrote:

> Hi,
> Is there a way to implement jquery datepicker with Django models. I am
> looking at http://jqueryui.com/datepicker/ but i am finding very
> difficult to apply it to django models. any help will be very much
> appreciated.
>
> Cheers
>
>
>  --
> 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/CAPCf-y735T-8%3DNVdePFU7UEmN_9SQmsLj9uWUeCQ%2B-dRUMNYjQ%40mail.gmail.com
> 
> .
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMHY-Kd5D_k8dCqcG8c_evJvN6EcdudwaTrDtt_5MpvkCzgtXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: datepicker

2015-05-26 Thread Peith Vergil
Actually, use the DateField instead of the CharField so you get server side
validation of the date input. It should just render as a text input on the
front-end.
On May 27, 2015 01:40, "Peith Vergil"  wrote:

> I don't think you do it with models. You do it with form fields. An easy
> way is to simply create a regular CharField, render it like usual. Then, on
> the front-end, you simply target that specific char field and initialize
> the datepicker on it.
> On May 27, 2015 01:31, "sum abiut"  wrote:
>
>> Hi,
>> Is there a way to implement jquery datepicker with Django models. I am
>> looking at http://jqueryui.com/datepicker/ but i am finding very
>> difficult to apply it to django models. any help will be very much
>> appreciated.
>>
>> Cheers
>>
>>
>>  --
>> 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/CAPCf-y735T-8%3DNVdePFU7UEmN_9SQmsLj9uWUeCQ%2B-dRUMNYjQ%40mail.gmail.com
>> 
>> .
>> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMHY-Kdie6Uc-qCbm6huoyG3Cu8Ez9Gsv9CVGYJEeJeXS2EM-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Gmail oAUTH application for Django

2015-05-26 Thread Luis Zárate
Why don't you use django-allauth?

http://www.intenct.nl/projects/django-allauth/





2015-05-26 7:48 GMT-06:00 Great Avenger Singh :

> Hello Django-People,
>
> I am writing a Gmail oAuth2 application with Django so  one can login to
> Gmail. (I have Desktop Python script ready with me)
>
> After doing some Google I am able to find following Tutorial:
>
>
> http://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/
>
> This explains everything I need but I guess there is some change in Django
> Working system from the time when this tutorial is written, Please correct
> me if I am wrong?
>
> Do I need to create Django Project for Gmail oAUTH or I should make it
> Django app?
>
>  --
> 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/86054741-65e6-4422-aad6-d3c9ccbc1cdc%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyORjtV%3D58Hd3X68wk1__b6Y0_BPBm%2BsC9gngX_P1uo4cg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Get Call Stacks for Classes in Models

2015-05-26 Thread Utkarsh

Hi!

So, there is a huge Django app with multiple classes in Model. I am 
interested in getting call stacks of some classes. I have few questions in 
the approach and few questions regarding the implementation. I am using 
Django 1.4.20 and python 2.7

1. What if we decide to write a decorator for the class/ methods? 
Ex. 
@trackitdown
Class A(models.Model):

or 
@trackitdown
def some_method(): # method in models.py

This is because I do not want to disturb the existing code. I wish to 
achieve following-
I. If it is a class, track all "calls" whenever QuerySetAPI methods, save, 
delete is called. 
II. while doing following-
objects =classWhichIsAManager()# overriding default manager Custom manager

this should be decorator's task.
III. override using get_query_set() , and save(), delete()

How do you see this approach? I obviously was not able to implement this 
because of peculiar behavior of Model and ModelBase.

2. Is it okay to decorate a class, define decorator as a class and override 
methods in it? How much is this encouraged?

3. If I use Mixins, and try to implement the same, I still do not get how 
do we override 
objects=classWhichIsAManager()

outside the model class? that too without loosing attributes of original 
model class.

4. Having said this, I wish to implement a library which will take care 
calls stacks of model classes/ methods. 

Is there a fundamental flaw in my approach? I can see that I am trying to 
play with some unknown business of ModelBase(Foreign Key constraints, etc) 
New approaches and comments are equally welcome!

-- 
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/ffe7bc52-66c7-40d6-b174-b7c724496a68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to pass a queryset for each different field Admin Inlines

2015-05-26 Thread Felipe
Someone can help me ?, he took days trying to fix this and nothing to get 
it, if I could just iterate a QuerySet each model choice of the form. The 
only thing achieved is that a queryset applies to all forms inline, but I 
need a different one for each inline.
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "value_option":
kwargs["queryset"] = request._obj_.category.attributes.all()
return super(AttributeInline, 
self).formfield_for_foreignkey(db_field, request, **kwargs)


-- 
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/50459949-79eb-4452-b6b9-386517669525%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Changing a form field's value during cleaning

2015-05-26 Thread Gergely Polonkai
Hello,

I'm currently having hard times changing a form field's value from within
the form's clean() method. I have already tried setting
self.initial[field_id] and manipulating the cleaned data by calling super's
clean method, change the required field (cleaned_data[field_id]) and
returning the modified dict, but all for no effect. Trying to change
self.data threw me an error saying data is immutable. Question is, is it
even possible, even if I had to tamper with ”protected/private”
properties/methods?

Should I be on the wrong track, I try to outline the problem:

I have a form with fields added programmatically in __init__(). The value
of these fields come from one of my models. It is highly possible that
another user puts one of the fields in approved state. If this happens, I
don't want the current user to be able to change its value, hence I raise a
validation error in the field's validate() method.

Now comes the tricky part. In this particular case I want three things to
happen:

• warn the user about the fact that the field has already been approved
(i.e. display the validation error message)
• render the input field as read only so the user can't modify it (well, at
least not in a trivial way)
• and revert the field's value to the one in the database

However, in case of a validation error the field's value remains the
”illegal” one the user just entered, and, as the input field is rendered
read only, there's no way for him to change it. Thus, I am trying to set it
during MyForm.clean() by walking through field errors looking form the
proper error code ('already_approved'), and once found, set it back to its
database value. This way I hope that my ValidationError remains (hence the
warning on the page) while resetting the unchangeable value so at the time
of the next submit it won't cause a problem.

Kind regards,
Gergely

-- 
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/CACczBUK2EEaHBaS7bS%3DJF8Ce35MBkrwugtRvZCJC9E_Ovk2Rqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Changing a form field's value during cleaning

2015-05-26 Thread Vijay Khemlani
If some of the fields are "already approved" and thus they can't be edited,
why are you rendering those as editable form fields in the first place?

On Tue, May 26, 2015 at 9:55 PM, Gergely Polonkai 
wrote:

> Hello,
>
> I'm currently having hard times changing a form field's value from within
> the form's clean() method. I have already tried setting
> self.initial[field_id] and manipulating the cleaned data by calling super's
> clean method, change the required field (cleaned_data[field_id]) and
> returning the modified dict, but all for no effect. Trying to change
> self.data threw me an error saying data is immutable. Question is, is it
> even possible, even if I had to tamper with ”protected/private”
> properties/methods?
>
> Should I be on the wrong track, I try to outline the problem:
>
> I have a form with fields added programmatically in __init__(). The value
> of these fields come from one of my models. It is highly possible that
> another user puts one of the fields in approved state. If this happens, I
> don't want the current user to be able to change its value, hence I raise a
> validation error in the field's validate() method.
>
> Now comes the tricky part. In this particular case I want three things to
> happen:
>
> • warn the user about the fact that the field has already been approved
> (i.e. display the validation error message)
> • render the input field as read only so the user can't modify it (well,
> at least not in a trivial way)
> • and revert the field's value to the one in the database
>
> However, in case of a validation error the field's value remains the
> ”illegal” one the user just entered, and, as the input field is rendered
> read only, there's no way for him to change it. Thus, I am trying to set it
> during MyForm.clean() by walking through field errors looking form the
> proper error code ('already_approved'), and once found, set it back to its
> database value. This way I hope that my ValidationError remains (hence the
> warning on the page) while resetting the unchangeable value so at the time
> of the next submit it won't cause a problem.
>
> Kind regards,
> Gergely
>
> --
> 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/CACczBUK2EEaHBaS7bS%3DJF8Ce35MBkrwugtRvZCJC9E_Ovk2Rqg%40mail.gmail.com
> 
> .
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2dZX1KWd-SQ1S9VJ%3DbK8bN9Xj1MKvb7jS-zNyvxSz3Aw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django-Taggit and the ListView

2015-05-26 Thread Lachlan Musicman
Hola,

I was planning on using Django taggit for tagging models.

http://django-taggit.readthedocs.org
https://github.com/alex/django-taggit

I am trying to get some sort of CBV (eg lListView of model's with tag x)
happening but it doesn't seem able to do this.

The app's views.py
https://github.com/alex/django-taggit/blob/develop/taggit/views.py

has a tagged_object_list function, but I can't seem to get it working and
can't find a test that might give me an indication.

So I tried re-creating it in my own views.py and y equivalent to this line:

return ListView.as_view(request, qs, **kwargs)

keeps throwing errors like "ListView.as_view takes exactly 1 argument"

And now I'm confused - this app is by Alex Gaynor, so I presume it's solid
and I'm the one making the mistake.

Can anyone give me an indication how either the taggit.views might be used
or how I might implement something like ListView.as_view(request, qs, **
kwargs)

Cheers
L.

--
let's build quiet armies friends, let's march on their glass towers...let's
build fallen cathedrals and make impractical plans

- GYBE

-- 
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/CAGBeqiPoEeEbpETfAmHq%3DAA2WkEHHbGO79NapXf8YAjA5y8nZQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django-Taggit and the ListView

2015-05-26 Thread James Schneider
>From a brief glance at the RTD (and assuming you are using CBV's), it looks
like you should create a standard ListView and then override get_queryset()
with the extra filter to narrow down the list of models retrieved:

http://django-taggit.readthedocs.org/en/latest/api.html#filtering

You can use a (?P[\w-]+) or whatever you want to name it to
capture a URL parameter specifying the desired tag, and pull that parameter
when adding the filter in get_queryset().

Something like this:


def get_queryset(self):
qs = super(ListViewName, self).get_queryset()
return qs.filter(tags__name=self.kwargs.get('tag_slug', None))


That works for filtering via a single tag (which sounds like what you are
trying to do). A non-matching slug will return an empty list, and a missing
slug will return all of the models without tags (I presume). For multiple
tags, you should either accept GET or POST parameters from a form
submission, unless you come up with some funky regex to capture multiple
tags via the URL (not recommended), and modify the get_queryset() call to
use __in rather than =.

There shouldn't be any need to pass extra parameters to the view call. A
typical ListViewName.as_view() should suffice. Everything you need should
be gathered via a form submission or a URL kwarg.

Full disclosure, I haven't worked with django-taggit at all, so I could be
completely wrong.

For completeness in my answer, in the event that I'm wrong, you can allow
passing of extra arguments to the as_view() call by overriding the
__init__() method of the view and adding in the extra arguments to the
overridden method:


def __init__(self, request, qs, **kwargs):
super(ListViewName, self)__init__(**kwargs) # call the regular
__init__() with the originally expected kwargs, notice that request and qs
are missing
self.request = request #is this the view request? It should already be
available via self.request
self.qs = qs


You may also want to look at django-filter or django-easyfilter to provide
a small form to allow users to search for tags, if needed.

HTH,

-James



On May 26, 2015 7:33 PM, "Lachlan Musicman"  wrote:

> Hola,
>
> I was planning on using Django taggit for tagging models.
>
> http://django-taggit.readthedocs.org
> https://github.com/alex/django-taggit
>
> I am trying to get some sort of CBV (eg lListView of model's with tag x)
> happening but it doesn't seem able to do this.
>
> The app's views.py
> https://github.com/alex/django-taggit/blob/develop/taggit/views.py
>
> has a tagged_object_list function, but I can't seem to get it working and
> can't find a test that might give me an indication.
>
> So I tried re-creating it in my own views.py and y equivalent to this line:
>
> return ListView.as_view(request, qs, **kwargs)
>
> keeps throwing errors like "ListView.as_view takes exactly 1 argument"
>
> And now I'm confused - this app is by Alex Gaynor, so I presume it's solid
> and I'm the one making the mistake.
>
> Can anyone give me an indication how either the taggit.views might be used
> or how I might implement something like ListView.as_view(request, qs, **
> kwargs)
>
> Cheers
> L.
>
> --
> let's build quiet armies friends, let's march on their glass
> towers...let's build fallen cathedrals and make impractical plans
>
> - GYBE
>
> --
> 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/CAGBeqiPoEeEbpETfAmHq%3DAA2WkEHHbGO79NapXf8YAjA5y8nZQ%40mail.gmail.com
> 
> .
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXG_-WqbJ9MiAJAqRLGCJex9Db0bTJ0N2nH-Zv%3DmEJ5GA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Changing a form field's value during cleaning

2015-05-26 Thread Gergely Polonkai
Because it is possible that user A will load the page, and user B will
approve the field.
On 27 May 2015 03:38, "Vijay Khemlani"  wrote:

> If some of the fields are "already approved" and thus they can't be
> edited, why are you rendering those as editable form fields in the first
> place?
>
> On Tue, May 26, 2015 at 9:55 PM, Gergely Polonkai 
> wrote:
>
>> Hello,
>>
>> I'm currently having hard times changing a form field's value from within
>> the form's clean() method. I have already tried setting
>> self.initial[field_id] and manipulating the cleaned data by calling super's
>> clean method, change the required field (cleaned_data[field_id]) and
>> returning the modified dict, but all for no effect. Trying to change
>> self.data threw me an error saying data is immutable. Question is, is it
>> even possible, even if I had to tamper with ”protected/private”
>> properties/methods?
>>
>> Should I be on the wrong track, I try to outline the problem:
>>
>> I have a form with fields added programmatically in __init__(). The value
>> of these fields come from one of my models. It is highly possible that
>> another user puts one of the fields in approved state. If this happens, I
>> don't want the current user to be able to change its value, hence I raise a
>> validation error in the field's validate() method.
>>
>> Now comes the tricky part. In this particular case I want three things to
>> happen:
>>
>> • warn the user about the fact that the field has already been approved
>> (i.e. display the validation error message)
>> • render the input field as read only so the user can't modify it (well,
>> at least not in a trivial way)
>> • and revert the field's value to the one in the database
>>
>> However, in case of a validation error the field's value remains the
>> ”illegal” one the user just entered, and, as the input field is rendered
>> read only, there's no way for him to change it. Thus, I am trying to set it
>> during MyForm.clean() by walking through field errors looking form the
>> proper error code ('already_approved'), and once found, set it back to its
>> database value. This way I hope that my ValidationError remains (hence the
>> warning on the page) while resetting the unchangeable value so at the time
>> of the next submit it won't cause a problem.
>>
>> Kind regards,
>> Gergely
>>
>> --
>> 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/CACczBUK2EEaHBaS7bS%3DJF8Ce35MBkrwugtRvZCJC9E_Ovk2Rqg%40mail.gmail.com
>> 
>> .
>> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALn3ei2dZX1KWd-SQ1S9VJ%3DbK8bN9Xj1MKvb7jS-zNyvxSz3Aw%40mail.gmail.com
> 
> .
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUJ32cOC09_oJ8WyZ_VciA9-tQgQ1T2MF4QMCf4QZ5qqnQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.