ModelForm unbound

2011-04-21 Thread Constantine
Hi

i've used some logic in clean_field methods, but when i've migrated to
ModelForm, was very surprised that clean methods does not invoked
after some investigation i realized that model instane does not makes
modelform bound automatically

i'm expect that model validation also triggered as pointed here
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-is-valid-method-and-errors
but models.py contradicts
def is_valid(self):
"""
Returns True if the form has no errors. Otherwise, False. If
errors are
being ignored, returns False.
"""
return self.is_bound and not bool(self.errors)

model with instance only WILL NOT trigger validation

-- 
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: ModelForm unbound

2011-04-21 Thread Constantine
Let me show example

on form i have two coerced fieds (ModelChoiceField)
queryset for second field based on first

so, using simpleform i can modify second queryset using
firstfield_clean
but using modelform i should do it twise:
in init for form instantiation and in field_clean for save
what about DRY?

> which presumably are already valid,
> otherwise they should not have been saved

db essentials could be invalid if there hard validation logic exists

On Apr 21, 7:35 pm, Daniel Roseman  wrote:
> On Thursday, April 21, 2011 8:16:36 AM UTC+1, Constantine wrote:
>
> > Hi
>
> > i've used some logic in clean_field methods, but when i've migrated to
> > ModelForm, was very surprised that clean methods does not invoked
> > after some investigation i realized that model instane does not makes
> > modelform bound automatically
>
> > i'm expect that model validation also triggered as pointed here
>
> >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-is-...
> > but models.py contradicts
> >     def is_valid(self):
> >         """
> >         Returns True if the form has no errors. Otherwise, False. If
> > errors are
> >         being ignored, returns False.
> >         """
> >         return self.is_bound and not bool(self.errors)
>
> > model with instance only WILL NOT trigger validation
>
> I'm not sure why that would surprise you, or why you would want it to work
> any other way. Form validation is for validating user input, not for
> checking already-saved instances (which presumably are already valid,
> otherwise they should not have been saved).
> --
> 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.



Request and null value

2011-06-05 Thread Constantine
Hi, a have a problem, but may be this is expected behaviour:

on client side i'm post:
$.post("my url",{myvar:null}...)

but on server side:
request.POST becomes {myvar:u'null'}

null deserialized to string. So, do i need to report a bug in tracker?

-- 
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: Request and null value

2011-06-06 Thread Constantine
Thanks, i've workaround this with empty string.
I was surprised when saw raw_post_data which looks very similar to GET
string. I confused this behaviour with JSON parser.

On 6 июн, 12:50, Jani Tiainen  wrote:
> On Sun, 2011-06-05 at 22:36 -0700, Constantine wrote:
> > Hi, a have a problem, but may be this is expected behaviour:
>
> > on client side i'm post:
> > $.post("my url",{myvar:null}...)
>
> > but on server side:
> > request.POST becomes {myvar:u'null'}
>
> > null deserialized to string. So, do i need to report a bug in tracker?
>
> It's not "deserialized" thus not a but but works as designed. HTTP
> POST/GET parameters are only strings. Nothing more, nothing less. Django
> doesn't do any magic by default.
>
> You can use some known notation to handle your data, like JSON which can
> serialize and deserialize data correctly.
>
> --
>
> Jani Tiainen

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



ModelForm save call with data and instance

2011-07-04 Thread Constantine
def view(request)
form = MyForm(request.POST, instance = MyModel(myfiled = 1))
if form.is_valid():
obj = form.save()

but POST will NEVER merged with instance i've looked through stack:

ModelForm's save() 
https://code.djangoproject.com/browser/django/trunk/django/forms/models.py#L362

save calls:

return save_instance(self, self.instance, self._meta.fields,
 fail_message, commit, >>>
construct=False <<<)

BUT construct=False and in save_instance
https://code.djangoproject.com/browser/django/trunk/django/forms/models.py#L68

if construct:
instance = construct_instance(form, instance, fields,
exclude)

in doesn't populate instance with cleaned data

Bug or Feature?

and if it's feature, how can I set values dynamically if it's not
specified in POST

-- 
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: ModelForm save call with data and instance

2011-07-05 Thread Constantine Linnick
I Found problem, it was triple collision:
pycharm debugging sideeffect, wrong inheritance in _init_, but most 
destructive was form fields: it overwrites instance values with None.
(if someone find this post from search 

anyway, thanks for reply

-- 
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/-/BBDLRNu6HNcJ.
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: Heroku push failed

2017-02-05 Thread Constantine Covtushenko
Hi Jonathan,

Sorry for stupid question but you did not specify that exactly.
Did you add that module in requirements.txt or requirements.pip?
Can you double check that?

On Sun, Feb 5, 2017 at 2:54 PM, Jonathan Cheng 
wrote:

> In Win10
> when i run "git push heroku master"
> the traceback showed:
> "python manage.py collectstatic"
> ,the python file
> ImportError: No module named 'markdown_deux'
>
> but i have installed the django-markdown-deux
> why i met this traceback?
>
>
> 
>
> --
> 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/21f408d7-48d3-4b34-918b-f5bb8e7f3a29%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boX_WU__Z7u48%3DLFFROCOKHiJf49J5Vmt0qMoDsxsYoavg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Djnago User login

2017-03-01 Thread Constantine Covtushenko
Hi Hossein,

I am not sure that understood you correctly.

Are you asking about the way how to handle two types of authentication?
One by user name and password,
an other by just username?


On Wed, Mar 1, 2017 at 4:05 PM, Hossein Torabi  wrote:

> is there any method that i have two kind of users that once log in with
> user name and password and other one login with just with user name?
>
> --
> 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/a4d0763b-0a0f-46c7-a75a-bd7f15ca7761%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXASTYMB6VdDP6iEiUANdpXSH7auf3kY8mdMGntd1X3sg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Djnago User login

2017-03-01 Thread Constantine Covtushenko
+1 for CustomAuth Backend solution.

In runtime Django checks all set backends in the order so I would suggest
to put your backend at the beginning of backend's list.

On Thu, Mar 2, 2017 at 12:05 AM, Shawn Milochik 
wrote:

> It takes a little fiddling, but you can log in a user however you want.
>
> https://docs.djangoproject.com/en/1.10/topics/auth/
> default/#how-to-log-a-user-in
>
> In short, you can call django.contrib.auth.login(request, user) and force
> a login without any authentication if you really wanted to. Given that, you
> can make your own auth backend (subclass the default one) that returns True
> for certain usernames without checking the value of the password field.
>
>
> --
> 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/CAOzwKwGNmQ9XL6T0Btm%3DhS0iXOasw17YPzZbsgngcRqgSU4b
> %3DQ%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXUEmrP1-KrrW-8z0sDL1%3DCO6Ojneh5%3DWUS-Vk5XHsuqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: "In menu" does not work - Can anybody help?

2017-05-10 Thread Constantine Covtushenko
Hi Lisa,

Can you please tell what application do you use for that?
Is it django-cms?

Regards,
Constantine C.

On Wed, May 10, 2017 at 10:28 AM,  wrote:

> Hi there,
> I have a problem with the "in menu" section of a child-page in django. The
> URL is www.tenag.de/arbeitshilfen/energierelevante-gesetze-
> normen-und-verordnungen/ and should stay like this but should not show in
> the menu of "Arbeitshilfen". If I erase the arrow in "Show in menu" the
> page is still shown in the menu. Can anybody help me out?
> Thanks Lisa
>
> --
> 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/ff82aa5c-43b4-43e4-a1df-997375953039%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ff82aa5c-43b4-43e4-a1df-997375953039%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Permissions for Anonymous Users in Django

2017-05-10 Thread Constantine Covtushenko
Hi Uzair,

Can you please provide some use cases when there is needed such behavior?

Regards,
Constantine C.

On Tue, May 9, 2017 at 6:56 AM, Uzair Tariq  wrote:

> Does the Django have support for permission for the anonymous users? Reference
> Topic Link
> <https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#authorization-for-inactive-users>
>  is
> making it ambiguous for me deciding between its support. Is it talking
> about a scenario where permission does support anonymous users and its
> possible consequences w.r.t inactive users?
>
> --
> 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/6bdc87ab-bc43-4a20-a988-1807f500c63b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6bdc87ab-bc43-4a20-a988-1807f500c63b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: "In menu" does not work - Can anybody help?

2017-05-11 Thread Constantine Covtushenko
I am not a huge expert of django-cms. I just got it in 1 project of mine.

And I ca  say that all works as expected.
It is difficult to describe what is wrong with your menu based on what you
provided.
May be you can bring some sort of screenshots here?

Regards,
Constantine C.

On Thu, May 11, 2017 at 10:08 AM,  wrote:

> For me it looks more like a bug of the cms. I mean for what reason is the
> button if it does not work? :S
>
> Am Mittwoch, 10. Mai 2017 13:17:05 UTC+2 schrieb lisa.f...@tenag.de:
>>
>> Hi there,
>> I have a problem with the "in menu" section of a child-page in django.
>> The URL is www.tenag.de/arbeitshilfen/energierelevante-gesetze-normen-
>> und-verordnungen/ and should stay like this but should not show in the
>> menu of "Arbeitshilfen". If I erase the arrow in "Show in menu" the page is
>> still shown in the menu. Can anybody help me out?
>> Thanks Lisa
>>
> --
> 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/7ad84619-a62a-4690-8aa9-4d86995e7316%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7ad84619-a62a-4690-8aa9-4d86995e7316%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boWYvqw%2BPAG%2B2-xBt9wzoHw1mMweF7RyBX1PLhrgnVji4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Permissions for Anonymous Users in Django

2017-05-11 Thread Constantine Covtushenko
Hi Uzair,

It seems like I see your point.
Let me head you on answer off your first question:
> Does the Django have support for permission for the anonymous users?

Open the link provided by you: Reference Topic Link
<https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#authorization-for-inactive-users>
and
look paragraph above. There you can find following:

Django’s permission framework does not have a place to store permissions
for anonymous users. However, the user object passed to an authentication
backend may be an django.contrib.auth.models.AnonymousUser
<https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.AnonymousUser>
object,
allowing the backend to specify custom authorization behavior for anonymous
users.

As you can see permissions for Anonymous user should be defined inside some
custom authentication backend logic.

I believe that you should write your own Authentication Backend to allow
what you need for Anonymous user cases.

Hope that helps.

Regards,
Constantine C.


On Thu, May 11, 2017 at 12:24 AM, Melvyn Sopacua 
wrote:

> On Wednesday 10 May 2017 09:49:48 Uzair Tariq wrote:
>
> > Consider a scenario in which an anonymous user search for the user
>
> > profiles on the google. He gets public profile link to different
>
> > social network which he can view as the anonymous user but if this
>
> > user is registered and authenticated user on the social site but his
>
> > profile is inactive at the moment he won't be able to view even the
>
> > public profiles as his permission to the profile will be revoke
>
> > thanks to the is_active authentication check. By default in this case
>
> > Anonymous user will have greater surfing space compared with the
>
> > inactive user.
>
>
>
> Negative.
>
>
>
> An inactive user cannot log in, so for all intents and purposes she is an
> Anonymous user.
>
>
>
> If you use a backend that allows logging in inactive users, then that's a
> bad choice to make. It's kind of the point of the is_active flag.
>
>
>
> So either don't use the feature (use a custom user model that has no
> is_active flag) or use it and embrace it.
>
>
>
> The reason for the is_active flag is that you can moderate bad conduct,
> lack of payments and so on. If you have no need for it, then that's a good
> case to implement a custom user model, but be aware, that you will have to
> delete staff accounts or unmark them as staff if they are no longer allowed
> to access to the admin.
>
> --
>
> Melvyn Sopacua
>
> --
> 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/5368536.rz2B7ec2LH%40devstation
> <https://groups.google.com/d/msgid/django-users/5368536.rz2B7ec2LH%40devstation?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boVcM3c2q2Hi%2BQJjJ%3D2BQ7Rq65HXRXoO3Tcc-3bBse1z_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Permissions for Anonymous Users in Django

2017-05-11 Thread Constantine Covtushenko
Hi Uzair,
Please find my answer in blue:

On Thu, May 11, 2017 at 9:10 PM, Uzair Tariq  wrote:

> A Bundle of thank Constantine Covtushenko now the working to
> Authentication Backend for anonymous and inactive users is clear. Just one
> last question does the scenario that i defined in my example when you asked
> for the use case fit this line from the same topic.
> * The support for anonymous users in the permission system allows for a
> scenario where anonymous users have permissions to do something while
> inactive authenticated users do not.*
> Can you explain your deduction( The semantics of the line ) from this line
> of the topic with an example?
>
Let us check terms:
Anonymous User - is one that is not authenticated. It refers to scenarios
when someone opens site pages. Even robots can be such users.

Inactive Authenticated User - is one that successfully logged in.

That is why we can distinguish between them - 'not logged in' VS 'logged
in'.
That is why it is said '*inactive authenticated users*'.

Examples:
1. Someone just opens any page with public access - Anonymous User case
2. A Person which is logged in but did not confirmed their email or
something to activate their account and then opens page with public access
 - Authenticated But Is Not Active User.

Hope that helps,


Regards,
Constantine C.



> On Tuesday, May 9, 2017 at 8:56:47 AM UTC+5, Uzair Tariq wrote:
>>
>> Does the Django have support for permission for the anonymous users? 
>> Reference
>> Topic Link
>> <https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#authorization-for-inactive-users>
>>  is
>> making it Uzair, for me deciding between its support. Is it talking
>> about a scenario where permission does support anonymous users and its
>> possible consequences w.r.t inactive users?
>>
> --
> 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/ms
> gid/django-users/4d116642-d2ed-4512-a2e8-dd44b715a76a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4d116642-d2ed-4512-a2e8-dd44b715a76a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boV%2BW%2BBykPctErg4tsPi6TjTRo1PGynCkaNJmK70Uwj%2BMA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Permissions for Anonymous Users in Django

2017-05-11 Thread Constantine Covtushenko
You are welcome :)

Have a fun with you project and Django.
Django is very great!

On Thu, May 11, 2017 at 10:44 PM, Uzair Tariq 
wrote:

> Thanks man! So basically my example and deduction of the sentence was
> right about the anonymous and inactive authenticated users where i stated
> that the anonymous may be able to view the public profile but if it's an
> inactive authenticated user because of some reason he may be directed to
> some other error page because of is_active() permission check and he wont
> be able to view even public profile because the whole system will logically
> be promoting about account activation or any sort of equivalent
> reason/error.
>
> On Tuesday, May 9, 2017 at 8:56:47 AM UTC+5, Uzair Tariq wrote:
>>
>> Does the Django have support for permission for the anonymous users? 
>> Reference
>> Topic Link
>> <https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#authorization-for-inactive-users>
>>  is
>> making it ambiguous for me deciding between its support. Is it talking
>> about a scenario where permission does support anonymous users and its
>> possible consequences w.r.t inactive users?
>>
> --
> 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/8a4851aa-77a5-4c9e-b0d6-dc31a85b3262%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8a4851aa-77a5-4c9e-b0d6-dc31a85b3262%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: View Function Signature?

2017-05-12 Thread Constantine Covtushenko
Hi,

Please check that link
<https://docs.djangoproject.com/en/1.11/topics/http/urls/#how-django-processes-a-request>
of documentation.
For me it was very helpful to understand all pieces of Request/Response
cycle.

Regards,
Constantine C.

On Fri, May 12, 2017 at 4:05 PM, nickeforos  wrote:

> I'm following the django tutorials and documentaion as well as the django
> book.
> In
> https://docs.djangoproject.com/en/1.11/topics/http/views/
> there is this view function:
> def current_datetime(request):
> now = datetime.datetime.now()
> html = "It is now %s." % now
> return HttpResponse(html)
>
> and in:
> http://djangobook.com/django-views-dynamic-content/http://
> djangobook.com/django-views-dynamic-content/
> there is this view function:
> def hours_ahead(request, offset):
> try:
> offset = int(offset)
> except ValueError:
> raise Http404()
> dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
> html = "In %s hour(s), it will be  %s." % (offset, dt)
> return HttpResponse(html)
>
> So in the view function I can pass *request* as well as an *argument*
> from the url but how does the signature of a view function look like?
> Where can I find it in the documentation?
> Is it possible to see such signatures in PyCharm?
>
> --
> 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/76227b4e-5de3-4ca1-a9c6-658c2ee69529%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/76227b4e-5de3-4ca1-a9c6-658c2ee69529%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: View Function Signature?

2017-05-12 Thread Constantine Covtushenko
Hi Nick,

As for me it is responsibility of the developer to define view function.
There is only one mandatory argument 'request'.
All other are based on the logic of view function and url patterns.

Say for view function that operates with entity might be natural to add
'id' as a second parameter.

At the same time for view function that shows blog might be natural to get
'year' as a second parameter.

And so on.

I hope that helps.

Regards,
Constantine C.

On Fri, May 12, 2017 at 5:10 PM, Nick Gilmour  wrote:

> Thanks for the link. I understand these examples but still I would like to
> see how a view function is defined.
>
> I also would like to see it in PyCharm. When I click on a view function in
> PyCharm I only see:
>
> def myview_function(request)
> Inferred type: (request: Any) -> HttpResponse
>
> I would expect to see something like this:
> view_function(request, *args, **kwargs)
>
> I've also looked in django's source but I cannot locate it.
>
> On Fri, May 12, 2017 at 3:05 PM, nickeforos  wrote:
>
>> I'm following the django tutorials and documentaion as well as the django
>> book.
>> In
>> https://docs.djangoproject.com/en/1.11/topics/http/views/
>> there is this view function:
>> def current_datetime(request):
>> now = datetime.datetime.now()
>> html = "It is now %s." % now
>> return HttpResponse(html)
>>
>> and in:
>> http://djangobook.com/django-views-dynamic-content/http://dj
>> angobook.com/django-views-dynamic-content/
>> there is this view function:
>> def hours_ahead(request, offset):
>> try:
>> offset = int(offset)
>> except ValueError:
>> raise Http404()
>> dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
>> html = "In %s hour(s), it will be  %s." % (offset, dt)
>> return HttpResponse(html)
>>
>> So in the view function I can pass *request* as well as an *argument*
>> from the url but how does the signature of a view function look like?
>> Where can I find it in the documentation?
>> Is it possible to see such signatures in PyCharm?
>>
>> --
>> 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/ms
>> gid/django-users/76227b4e-5de3-4ca1-a9c6-658c2ee69529%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/76227b4e-5de3-4ca1-a9c6-658c2ee69529%40googlegroups.com?utm_medium=email&utm_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/CAH-droyZRQNwUA39G7y9fgcodtFoO_
> pn1OTgO0s1ANDsn0pRtw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAH-droyZRQNwUA39G7y9fgcodtFoO_pn1OTgO0s1ANDsn0pRtw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Trigger receiver signal on Proxy model

2017-05-12 Thread Constantine Covtushenko
Hi,

It is supposed to run 'index_elastic' when you save 'Item' entity.
And to run 'new_index_elastic' when you save 'Newmodel' entity.
May be the reason why you do not see proper logs that in your code all
operations with entity are done based on 'Item' class?

Hope that helps.

Regards,
Constantine C.


On Fri, May 12, 2017 at 8:23 AM, Yarnball  wrote:

> I'm using a proxy model, so that I can use Elastic search on the same
> model using two different serialisers.
>
> However, the new_index_elastic function never runs (ie I never see the
> print, and my NewModel never gets indexed).
>
> How would I do this?
>
> class Item(EsIndexable, models.Model):
> title = models.CharField( blank=True)
> tag = models.ManyToManyField('Tag', blank=True)
>
> class Elasticsearch(EsIndexable.Elasticsearch):
> serializer_class = ItemEsSerializer
> fields = ['title', 'tag']
> @receiver(post_save, sender= Item)def index_elastic(instance, **kwargs):
> instance.es.do_index()
> class Newmodel(Item):
> class Meta:
> proxy = True
> class Elasticsearch(EsIndexable.Elasticsearch):
> serializer_class = NewModelEsSerializer
> fields = ['title', 'tag']
> @receiver(post_save, sender= Newmodel)def new_index_elastic(instance, 
> **kwargs):
> print('Index proxy')
> instance.es.do_index()
>
> --
> 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/967390f9-5c81-4f0d-8cb5-9c24a9f88466%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/967390f9-5c81-4f0d-8cb5-9c24a9f88466%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Need help in Django User Model customization and authentication

2017-05-13 Thread Constantine Covtushenko
Hi Ajat,

It was not clear to me why you do not use 'Extending the existing User
model' approach, described here
<https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#extending-the-existing-user-model>
.

For me it works very well in almost all cases.
And if you go that way then authentication/authorization based questions
should not bring any worries at all.

But may be I missed something.
If so, please provide us with more concrete questions.

Regards,
Constantine C.

On Sat, May 13, 2017 at 4:23 PM, Ajat Prabha 
wrote:

> Hello everyone,
> I'm creating a payment gateway to make transactions on my college campus
> go cashless. It can be used to pay library dues, stationary charges, etc.
> The user will add money to a central account and then he/she can use that
> money virtually. I chose Django because of its security. But as I need 3
> groups of users viz. Faculty, Student and Staff, I'm having trouble to
> implement this in the best possible way. I fix one thing, the other gets
> disturbed. I'm new to Django, so I don't have much experience. I'm
> comfortable with views, basic models, etc. But this User customization, I
> can't get it right.
>
> I'm attaching a representational User model (any suggestions are welcome),
> please have a look. All the 3 groups will have certain fields common and
> certain fields specific to that group only like roll_number/employee_code
> and permission_sets(in case the system is later used for access to labs,
> etc.). The fields at below of the image will be common to all groups.
>
>
> <https://lh3.googleusercontent.com/-ApmIsfCMgnY/WRcInaw2xrI/A94/sLaL-TCzPswVdAb_zKgRtnwEj8KEa4yeACLcB/s1600/IMG_20170513_175313.jpg>
>
> I also tried this
> <https://drive.google.com/open?id=0Bz8W8OncbJROWHZLUXhsTmdETlU> customization 
> which
> worked but then I had issues in Django admin view where the password was
> stored in plain hashed value. I think it has something to do with
> reimplementing ReadOnlyPasswordHashWidget method declared in
> django.contrib.auth.forms but I'm not sure!
>
> I chose Django in the first place for security reasons and I'm not able to
> get it right.
> Can someone please help me out.
>
> Thanks!
>
> --
> 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/a98d6c25-68e0-49f6-acf1-1267e610281a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a98d6c25-68e0-49f6-acf1-1267e610281a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boU%3D339EOU2L33EAg-jeNPPE%3Dm%2Bp1_ouQH4kx0ivJVO_8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Matching query does not exist after a post_data signal, but in fact does exist when visiting the url sent by the query

2017-05-16 Thread Constantine Covtushenko
Hi, François-Xavier

I believe that the reason of that is a transaction that is not committed
yet  when your code reaches 'post_save' listener.
And when you use 'requests' library there is nothing in the DB yet.

And I am just curios why there is a need of saving 'admin view' in the DB?

Regards,
Constantine C.

On Tue, May 16, 2017 at 10:17 PM, François-Xavier Cao 
wrote:

> Hi everone,
>
>
> I started to code a two-apps django project. ModelA belongs to appone and
> ModelB belongs to apptwo. My purpose is to create a ModelA instance
> everytime that the user creates a ModelB instance. And the value of a
> ModelA CharField (that is ckeditor widgeted) must be the source code of a
> ModelB admin view. I used a post_data signal to link a function of creation
> for that. The problem is that i use the id of each instance of ModelB in
> order to create the good content for each instance of ModelA. When I try to
> use a string of the url sending the id parameter, the content field has for
> value the source code of the debug page
>
> (error 500, DoesNotExist at /admin/apptwo/modelb/my_view/ref=76, [76 is
> an example] ModelB matching query does not exist. Exception location :
> /home/me/Desktop/env/lib/python3.5/site-packages/django/db/models/query.py
> in get, line 385)
>
> But when I try to visit the url "http://localhost:8000//admin/
> apptwo/modelb/my_view/ref=76", or when I hardcode the url, without a str(
> instance.id), the page exists and everything works perfectly.
>
> I don't understand why.
>
> Could anybody give me some help to solve this problem ?
>
> Thanks in advance,
>
> --
>
> PS :
>
> The first app has a model.py that contains the following code :
>
>
> from django.db import models
> from django.contrib.auth.models import Userfrom registre.models import *
> class ModelA(models.Model):
> content = models.CharField(max_length=255, null=True)
> def __str__(self):
> return "ModelA : " + str(self.id)
>
>
>
>
> the admin.py of this first app also contains :
>
>
> from django.contrib import admin
> from appone.models import *
> from apptwo.models import ModelB
> from django.http import HttpResponse
> from django.template.response import TemplateResponse
> from django.conf.urls import url
> from registre import views
> from django.db.models.signals import post_save
> from django.dispatch import receiver
> import datetime
> from django.contrib.auth.models import User
> from django import forms
> from ckeditor.widgets import CKEditorWidget
> from django.template.loader import render_to_string
> import requests
>
> class ModelAAdminForm(forms.ModelForm):
> content = forms.CharField(widget=CKEditorWidget())
> class Meta:
> model = ModelA
> fields = '__all__'
>
> class ModelAAdmin(admin.ModelAdmin):
> form = ModelAAdminForm
>
> def create_A(sender, instance, **kwargs):
> string = "http://localhost:8000/admin/apptwo/modelb/my_view/ref="; + 
> str(instance.id)
> r = requests.get(string)
> ModelA.objects.create(contenu=r.text.encode('utf-8'))
>
> post_save.connect(create_A, sender=ModelB)
>
> admin.site.register(ModelA, ModelAAdmin)
>
>
>
>
>
> the second app (apptwo) has a models.py like this :
>
>
>
> from django.db import models
> from django.contrib.auth.models import User
>
> class ModelB(models.Model):
> owner = models.ForeignKey(User, null=True)
> name = models.CharField(max_length=255, null=True)
>
> def __str__(self):
> return self.name
>
>
>
>
> and an admin.py that contains :
>
>
>
> from django.contrib import admin
> from appone.models import *
> from apptwo.models import *
> import datetime
> from django.conf.urls import url, include
> from django.template.response import TemplateResponse
>
> class ModelBAdmin(admin.ModelAdmin):
>
> def get_queryset(self, request):
> qs = super(ModelB, self).get_queryset(request)
> if request.user.is_superuser:
> return qs
> return qs.filter(owner=request.user)
>
> def save_model(self, request, obj, form, change):
> obj.owner = request.user
> obj.save()
>
> def get_urls(self):
> urls = super(ModelBAdmin, self).get_urls()
> my_urls = [
> url(r'^my_view/ref=(?P\d+)$', self.my_view),
> ]
> return my_urls + urls
>
> def my_view(self, request, id):
> context = 

Re: Email conformation problem

2017-05-16 Thread Constantine Covtushenko
Hi, Ismail

Did you try:

*instance.user.email*?

I hope it should be what you need.

Regards,
Constantine C.

On Mon, May 15, 2017 at 3:47 PM, Ismail Sarenkapic 
wrote:

> from django.conf import settings
> from django.contrib.auth.models import (
> BaseUserManager, AbstractBaseUser
> )
> from django.contrib import messages
> from django.core.mail import send_mail
> from django.conf import settings
> from django.core.validators import RegexValidator
> from django.db import models
> from django.db.models.signals import post_save
> # Create your models here.
> from .utils import code_generator
>
> USERNAME_REGEX = '^[a-zA-Z0-9.+-]*$'
>
> class MyUserManager(BaseUserManager):
> def create_user(self, username, email, password=None):
> """
> Creates and saves a User with the given email, date of
> birth and password.
> """
> if not email:
> raise ValueError('Users must have an email address')
>
> user = self.model(
> username = username,
> email=self.normalize_email(email),
> )
>
> user.set_password(password)
> user.save(using=self._db)
> return user
>
> def create_superuser(self, username, email, password):
> """
> Creates and saves a superuser with the given email, date of
> birth and password.
> """
> user = self.create_user(
> username,
> email,
> password=password,
> )
> user.is_admin = True
> user.is_staff = True
> user.save(using=self._db)
> return user
>
>
> def get_email_field_name(self, email):
> email_string = str(self.email)
> return email_string
>
> class MyUser(AbstractBaseUser):
> username = models.CharField(
> max_length=255,
> validators=[
> RegexValidator(
> regex = USERNAME_REGEX,
> message = 'Username must be Alpahnumeric or contain 
> any of the following: ". @ + -" ',
> code='invalid_username'
> )],
> unique=True,
> )
> email = models.EmailField(
> verbose_name='email address',
> max_length=255,
> unique=True,
> )
> zipcode   = models.CharField(max_length=120, default="92660")
> is_active = models.BooleanField(default=True)
> is_staff = models.BooleanField(default=False)
> is_admin = models.BooleanField(default=False)
>
> objects = MyUserManager()
>
> USERNAME_FIELD = 'username'
> REQUIRED_FIELDS = ['email']
>
> def get_full_name(self):
> # The user is identified by their email address
> return self.email
>
> def get_short_name(self):
> # The user is identified by their email address
> return self.email
>
> def __str__(self):  # __unicode__ on Python 2
> return self.email
>
> def has_perm(self, perm, obj=None):
> "Does the user have a specific permission?"
> # Simplest possible answer: Yes, always
> return True
>
> def has_module_perms(self, app_label):
> "Does the user have permissions to view the app `app_label`?"
> # Simplest possible answer: Yes, always
> return True
>
>
>
> # @property
> # def is_staff(self):
> # "Is the user a member of staff?"
> # # Simplest possible answer: All admins are staff
> # return self.is_admin
>
>
>
> class ActivationProfile(models.Model):
> user= models.ForeignKey(settings.AUTH_USER_MODEL)
> key = models.CharField(max_length=120)
> expired = models.BooleanField(default=False)
>
> def save(self, *args, **kwargs):
> self.key = code_generator()
> super(ActivationProfile, self).save(*args, **kwargs)
>
>
> def post_save_activation_receiver(sender, instance, created, *args, **kwargs):
> if created:
> #send email
> subject = 'Registration'
> message = "http://127.0.0.1:8000/activate/{0}".format(instance.key)
> from_email = settings.EMAIL_HOST_USER
> recipient_list = ['UserEmail']
> print(recipient_list)
>
> send_mail(subject, message, from_email, 
> recipient_list,fail_silently=True)
>
> post_save.connect(p

Re: Email conformation problem

2017-05-16 Thread Constantine Covtushenko
It is not a Django related question, sorry.
I can just suggest to look in 'SPAM' filters in you mailing agent.

On Wed, May 17, 2017 at 9:24 AM, Ismail Sarenkapic 
wrote:

> I already fixed the problem tnx.
> but i still dont know why are my emails treated like potential fishing
> content, can you help me with that?
>
>
> On Wednesday, May 17, 2017 at 8:21:22 AM UTC+2, Constantine Covtushenko
> wrote:
>>
>> Hi, Ismail
>>
>> Did you try:
>>
>> *instance.user.email*?
>>
>> I hope it should be what you need.
>>
>> Regards,
>> Constantine C.
>>
>> On Mon, May 15, 2017 at 3:47 PM, Ismail Sarenkapic 
>> wrote:
>>
>>> from django.conf import settings
>>> from django.contrib.auth.models import (
>>> BaseUserManager, AbstractBaseUser
>>> )
>>> from django.contrib import messages
>>> from django.core.mail import send_mail
>>> from django.conf import settings
>>> from django.core.validators import RegexValidator
>>> from django.db import models
>>> from django.db.models.signals import post_save
>>> # Create your models here.
>>> from .utils import code_generator
>>>
>>> USERNAME_REGEX = '^[a-zA-Z0-9.+-]*$'
>>>
>>> class MyUserManager(BaseUserManager):
>>> def create_user(self, username, email, password=None):
>>> """
>>> Creates and saves a User with the given email, date of
>>> birth and password.
>>> """
>>> if not email:
>>> raise ValueError('Users must have an email address')
>>>
>>> user = self.model(
>>> username = username,
>>> email=self.normalize_email(email),
>>> )
>>>
>>> user.set_password(password)
>>> user.save(using=self._db)
>>> return user
>>>
>>> def create_superuser(self, username, email, password):
>>> """
>>> Creates and saves a superuser with the given email, date of
>>> birth and password.
>>> """
>>> user = self.create_user(
>>> username,
>>> email,
>>> password=password,
>>> )
>>> user.is_admin = True
>>> user.is_staff = True
>>> user.save(using=self._db)
>>> return user
>>>
>>>
>>> def get_email_field_name(self, email):
>>> email_string = str(self.email)
>>> return email_string
>>>
>>> class MyUser(AbstractBaseUser):
>>> username = models.CharField(
>>> max_length=255,
>>> validators=[
>>> RegexValidator(
>>> regex = USERNAME_REGEX,
>>> message = 'Username must be Alpahnumeric or contain 
>>> any of the following: ". @ + -" ',
>>> code='invalid_username'
>>> )],
>>> unique=True,
>>> )
>>> email = models.EmailField(
>>> verbose_name='email address',
>>> max_length=255,
>>> unique=True,
>>> )
>>> zipcode   = models.CharField(max_length=120, default="92660")
>>> is_active = models.BooleanField(default=True)
>>> is_staff = models.BooleanField(default=False)
>>> is_admin = models.BooleanField(default=False)
>>>
>>> objects = MyUserManager()
>>>
>>> USERNAME_FIELD = 'username'
>>> REQUIRED_FIELDS = ['email']
>>>
>>> def get_full_name(self):
>>> # The user is identified by their email address
>>> return self.email
>>>
>>> def get_short_name(self):
>>> # The user is identified by their email address
>>> return self.email
>>>
>>> def __str__(self):  # __unicode__ on Python 2
>>> return self.email
>>>
>>> def has_perm(self, perm, obj=None):
>>> "Does the user have a specific permission?"
>>> # Simplest possible answer: Yes, always
>>> return True
>>>
>>> def has_module_perms(self, app

Re: Email conformation problem

2017-05-17 Thread Constantine Covtushenko
Hi Ismail,

Thank you for your suggestion.
Will get it into consideration for future responds.

Have a nice day to all.

On Wed, May 17, 2017 at 10:55 AM, m712 - Developer <
comeon@getbackinthe.kitchen> wrote:

> That's a pretty rude way to reply for someone who is asking questions.
> Many major email providers mark emails from servers without a PTR record to
> their domains as "spam".
> On May 17, 2017 9:52 AM, Ismail Sarenkapic  wrote:
>
> lol, It is Django related question and can be solved with some of third
> party libraries like allauth, scoialauth etc.
> Please don't replay to the posts when you don't know what it is about.tnx
> again
>
> On Wednesday, May 17, 2017 at 8:41:05 AM UTC+2, Constantine Covtushenko
> wrote:
>
> It is not a Django related question, sorry.
> I can just suggest to look in 'SPAM' filters in you mailing agent.
>
> On Wed, May 17, 2017 at 9:24 AM, Ismail Sarenkapic 
> wrote:
>
> I already fixed the problem tnx.
> but i still dont know why are my emails treated like potential fishing
> content, can you help me with that?
>
>
> On Wednesday, May 17, 2017 at 8:21:22 AM UTC+2, Constantine Covtushenko
> wrote:
>
> Hi, Ismail
>
> Did you try:
>
> *instance.user.email*?
>
> I hope it should be what you need.
>
> Regards,
> Constantine C.
>
> On Mon, May 15, 2017 at 3:47 PM, Ismail Sarenkapic 
> wrote:
>
> from django.conf import settings
> from django.contrib.auth.models import (
> BaseUserManager, AbstractBaseUser
> )
> from django.contrib import messages
> from django.core.mail import send_mail
> from django.conf import settings
> from django.core.validators import RegexValidator
> from django.db import models
> from django.db.models.signals import post_save
> # Create your models here.
> from .utils import code_generator
>
> USERNAME_REGEX = '^[a-zA-Z0-9.+-]*$'
>
> class MyUserManager(BaseUserManager):
> def create_user(self, username, email, password=None):
> """
> Creates and saves a User with the given email, date of
> birth and password.
> """
> if not email:
> raise ValueError('Users must have an email address')
>
> user = self.model(
> username = username,
> email=self.normalize_email(email),
> )
>
> user.set_password(password)
> user.save(using=self._db)
> return user
>
> def create_superuser(self, username, email, password):
> """
> Creates and saves a superuser with the given email, date of
> birth and password.
> """
> user = self.create_user(
> username,
> email,
> password=password,
> )
> user.is_admin = True
> user.is_staff = True
> user.save(using=self._db)
> return user
>
>
> def get_email_field_name(self, email):
> email_string = str(self.email)
> return email_string
>
> class MyUser(AbstractBaseUser):
> username = models.CharField(
> max_length=255,
> validators=[
> RegexValidator(
> regex = USERNAME_REGEX,
> message = 'Username must be Alpahnumeric or contain 
> any of the following: ". @ + -" ',
> code='invalid_username'
> )],
> unique=True,
> )
> email = models.EmailField(
> verbose_name='email address',
> max_length=255,
> unique=True,
> )
> zipcode   = models.CharField(max_length=120, default="92660")
> is_active = models.BooleanField(default=True)
> is_staff = models.BooleanField(default=False)
> is_admin = models.BooleanField(default=False)
>
> objects = MyUserManager()
>
> USERNAME_FIELD = 'username'
> REQUIRED_FIELDS = ['email']
>
> def get_full_name(self):
> # The user is identified by their email address
> return self.email
>
> def get_short_name(self):
> # The user is identified by their email address
> return self.email
>
> def __str__(self):  # __unicode__ on Python 2
> return self.email
>
> def has_perm(self, perm, obj=None):
> "Does the user have a specific permission?"
> # Simplest possible answer: Yes, always
> return True
>
> def has_module_perms(self

Re: Model design question

2017-06-25 Thread Constantine Covtushenko
Hi Mark,

I have some questions to you.
1. Does any of MetaData have predefined list of MetaDataValues?
2. Can MetaDataValue be assigned to many Documents or it is specific to
particular Document?

Regards,
Constantine C.

On Sun, Jun 25, 2017 at 6:20 PM, Mark Phillips 
wrote:

> I have a class Document that uploads a document. I have a class MetaData
> that is the name for some metadata for that document. Since a MetaData can
> have one or more values, there is another class called MetaDataValue that
> has a ForeignKey to MetaData. Finally, there is a class
> DocumentMetaDataValue that links these three tables. It almost works...but
> in the Admin screen when I want to add something to the DocumentMetaData
> class I can select one or more documents from a drop down list (good!), and
> one or more Metadata from a dropdown list (good), and I can select one or
> more MetaDataValues from a drop down list (good). However, the bad news is
> that the relationship between the MetaData and MetaDataValue is not
> preserved.
>
> For example, say I have MetaData 'people' with values John, Mark, Allison,
> and 'events' with values birthday, wedding, funeral. When I add a
> DocumentMetaData, I want to select 'people' from the MetaData dropdown, and
> then only the MetaDataValues for 'people' should be displayed in the
> MetaDataValues dropdown. Instead, what I get is all the MetaDataValues
> regardless of the associated MetaData, and I can add a MetaDataValue of
> John to a document under the Metadata label of 'events'. What am I missing
> in the relationship between the MetaDataValues class and the MetaData class?
>
> These are my classes. I have removed some of the extraneous fields and
> methods in the classes for clarity.
>
> class MetaData(models.Model):
> metadata_id = models.AutoField(primary_key = True)
> name = models.CharField('metadata name', max_length=200)
>
> class MetaDataValue(models.Model):
> metadata = models.ForeignKey(MetaData, on_delete=models.CASCADE,)
> value = models.CharField('value', max_length=200)
>
> class Document(models.Model):
> document_id = models.AutoField(primary_key=True)
> title = models.CharField('title', max_length=200)
>
> class DocumentMetaData(models.Model):
> document = models.ManyToManyField(Document)
> metadata = models.ManyToManyField(MetaData)
> metadatavalue = models.ManyToManyField(MetaDataValue)
>
> Thanks!
>
> --
> 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/CAEqej2PO2bMW%2BZ%3DPJVy66%3DWspm6E7zetGrYHyxjg-
> 9iOjBmzaQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAEqej2PO2bMW%2BZ%3DPJVy66%3DWspm6E7zetGrYHyxjg-9iOjBmzaQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: add users to google group django

2017-07-01 Thread Constantine Covtushenko
Hi Brian,

A quick overview of your requirements.

There should be a signup flow that adds user email to specific Google
Group. So basically you are trying to get just emails from user. And you
are not going to verify emails, activate/deactivate users, add secured
section to you site, except admin panel. Am I correct?

If so then I would do it creating gateway which should wrap all Google
Group specific code and just put it in 'is_valid' form case, for instance:

> GroupList.add(user_email)

where GroupList mentioned gateway.

I checked Google Settings API quickstart for python by this link
<https://developers.google.com/admin-sdk/groups-settings/quickstart/python>.
It seems to me that creating GroupList should very straightforward task.

Please consider my response as a suggestion only. It is just basic idea.

Regards,
Constantine C.


On Fri, Jun 30, 2017 at 10:44 AM, Brian Lee  wrote:

> I have a quick question about handling email updates using Django. My
> organization uses a Google Group to send mass emails to those added to the
> email list, and I was looking to add a 'sign up' widget to the footer of
> the website (It's a non-buisness Google Group). Is it possible to utilize
> Google Group's API and Django to create a system where Django automatically
> adds emails to the Google Group? If so, how do you all suggest I go about
> implementing the feature?
>
> --
> 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/730d41bf-4fed-4626-be42-8b007ca26ddf%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/730d41bf-4fed-4626-be42-8b007ca26ddf%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Keep logged in accross Sites

2017-07-01 Thread Constantine Covtushenko
Hello Pablo,

+1 to your solution

Regards,
Constantine C.

On Fri, Jun 30, 2017 at 9:06 AM, Pablo Camino Bueno 
wrote:

> Hello,
>
> I'm using Django Sites framework to hadle different sites, with the same
> users.
>
> I'd like to add a link to switch between my sites, but I don't want to get
> redirected to login view. What is the best way? should I add a view that
> logs the user in the destination site and redirect?
>
> --
> 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/896d69c6-40da-4c85-bb0d-91c589ba7924%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/896d69c6-40da-4c85-bb0d-91c589ba7924%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Built-in logging module may lead to memory leak?

2017-07-01 Thread Constantine Covtushenko
Hello,

Can you please print here a code snippet where you are using:
> logger = logging.getLogger(__name__)

Regards,
Constantine C.

On Thu, Jun 29, 2017 at 11:29 PM, Yp Xie  wrote:

> Hi guys,
>
> I'm using the python built-in logging module in a django project. Using
> dictConfig, the configuration in settings.py is like this:
>
> 
> 
> ---
> LOGGING = {
> 'version': 1,
> 'disable_existing_loggers': False,
> 'handlers': {
> 'mail_admins': {
> 'level': 'ERROR',
> 'class': 'django.utils.log.AdminEmailHandler'
> },
> 'console': {
> 'level': 'DEBUG',
> 'class': 'logging.StreamHandler',
> 'formatter': 'verbose'
> },
> 'logfile': {
> 'level': 'DEBUG',
> 'class': 'logging.handlers.RotatingFileHandler',
> 'filename': os.path.join(ROOT_DIR(), 'django.log'),
> 'maxBytes': 1024 * 1024 * 10,
> 'backupCount': 5,
> 'formatter': 'verbose',
> },
> }
> 'formatters': {
> 'verbose': {
> 'format': '#
> #\n'
>   '%(levelname)s | %(asctime)s | %(process)s |
> %(module)s | %(name)s.%(funcName)s:%(lineno)d | \n%(message)s',
> 'datefmt': '%Y-%m-%d %H:%M:%S',
> },
> 'simple': {
> 'format': '%(levename)s | %(asctime)s | %(message)s'
> },
> },
> 'loggers': {
> 'django': {
> 'handlers': ['console', 'logfile'],
> 'level': 'INFO',
> },
> 'django.request': {
> 'handlers': ['console', 'mail_admins'],
> 'level': 'ERROR',
> 'propagate': False
> },
> 'project_name': {
> 'handlers': ['console', 'logfile'],
> 'level': 'DEBUG',
> 'propagate': True,
> },
> 'utility': {
> 'handlers': ['console', 'logfile'],
> 'level': 'DEBUG',
> 'propagate': True,
> },
> }
> }
>
> LOGGING_CONFIG = None
>
> import logging.config
>
> logging.config.dictConfig(LOGGING)
> 
> 
> --
>
> And I use logger = logging.getLogger(__name__) in the code under
> 'project_name' module.
> And I find it causes huge memory leak problem, the memory usage keeps
> growing and never goes down.
>
> if I replace the logger.info() part with a simple print() function, the
> memory usage is small and stable, so I guess it's the logging module that
> should to blame.
>
> But it's a core python built-in module, I don't think there is a huge
> memory leak problem without others point it out.
> The only useful infomation of google results I found is
> https://www.codeday.top/2017/02/10/12540.html
>
> So I used objgraph to detect if the Logger type numbers kept growing, but
> the result suggested that no obvious leaking types.
>
> I've been in this situation for almost a week, and still can't work it out.
>
> Anyone can give me some hints on this?
>
> Thanks!
>
> YP
>
>
>
>
> --
> 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/28172cbd-ce76-499e-a2c1-38eb9af6c0b4%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/28172cbd-ce76-499e-a2c1-38eb9af6c0b4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Keep logged in accross Sites

2017-07-06 Thread Constantine Covtushenko
Hi Pablo,

As suggested Larry this can be like SSO implementation in one of sites
hosted by your Django server.

But this can be done in more simple way because all sites are hosted within
the same Django server.

Possible Workflow:
===

Terms

'SSO Site' - one of the sites which we should specify as main SSO server -
main(central) application.
'Some Site' - any other site hosted on the same Django project except SSO
site.

1. on Some Site user clicks 'Login'
2. SSO Site redirects user to soo view of SSO Site
3. sso view checks if user already logged in
4. if not redirects user on login page of SSO Site
5. sso view generates one time token and redirects user back on
authenticate view of Some Site
6. authenticate view checks for token and if token valid and user was
redirected from SSO Site retrieves user from that token and authenticate it
into current session of Some Site.

I did not not find any way how to login user to all sites in advance.
Session token stores in browser cookies and user authentication should be
finished on the page that belongs to Some Site. User should initiate that
login process either explicitly by clicking on 'Login' link or implicitly
by redirecting from view that require authorization.

For the same reason I did not find how to request SSO from the page which
is not belongs to domain for which user should be authenticated as you
asked below.

Does it make any sense to you?

Regards,
Constantine C.


On Wed, Jul 5, 2017 at 8:52 AM, Larry Martell 
wrote:

> On Wed, Jul 5, 2017 at 7:25 AM, Pablo Camino Bueno
>  wrote:
> > Hi Constantine,
> >
> > Do you know how to implement this? I'd need to login the user in a domain
> > that is not the one the view was reached from.
> >
> > Could it be building a custom authentication backend that somehow logs
> the
> > user in all the sites?
>
> Sounds like you are talking about Single Sign On (SSO). Google that
> and you will find many ways to implement that.
>
> --
> 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/CACwCsY4NSu72yie-56Dq%3DO0%3D%
> 2B_hL2iNHjmfefQFvY0v2CX_Bcw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Updating an instance.

2017-09-29 Thread Constantine Covtushenko
Dear Mitui,

I saw 2 questions in your inquiry:
1. Regarding to Form behaviour
2. Regarding to log message

Let me clarify second:
Provided message said that server responded with 302 - redirect response.
It is correct as you said in your view method:
return HttpResponseRedirect('/login/response/'+str(a.userName.username))

Now is about first.
You printed 'using instance argument'. I asume that you are looking of a
way add user info to POST data using form. It does not work in this way.
That is why user info is cleared.

Initial value is used to pre populate form when it is no POST data yet,
like when you generate form on GET response.

To get what you need I would suggest add user info differently.
You have some options here.

1 - change your form - remove user field from it. You did not provide code
of your form. But I believe that you are using user field in the form.
2 - add user info to POST query. It is not recommended way as this POST
QuerySet is immutable. So to do that you need to create new QuerySet from
previous one and put user info there.

I hope that make some sense.

Regards,
Constantine C.

On Fri, Sep 29, 2017 at 3:11 PM, Mitul Tyagi  wrote:

> 
> {% csrf_token %}
> 
> 1st City: {{form.city1}}
> 2nd City: {{form.city2}}
> 3rd City: {{form.city3}}
> 4th City: {{form.city4}}
> 5th City: {{form.city5}}
>
> 
> Is the template part.
>
> On Saturday, September 30, 2017 at 12:16:07 AM UTC+5:30, Mitul Tyagi wrote:
>>
>> Problem 1 :
>> I have a model with  six fields. One is userName and other five are five
>> favourite cities.I want to update these five citiesbut when I
>> update them using instance argument the userName becomes NONEI am using
>> the id field to updatethe cities are updated for the id but the
>> userName is lost. Any help for that..The code I am using is
>> "
>> def Update(request, city_id):
>> if request.method == "POST":
>> a= City.objects.get(pk= int(city_id))
>> print "User Updated is : ",a.userName.username
>>
>> f = CityForm(request.POST, instance=a, initial={'userName.':
>> str(a.userName.username)})
>> f.save()
>> return HttpResponseRedirect('/login/r
>> esponse/'+str(a.userName.username))
>> else:
>> all_city = City.objects.all()
>> for city in all_city:
>> if int(city.pk) == int(city_id):
>> a = city
>> print "User: ",a.userName.username
>> form_class = CityForm(initial={'userName': a.userName})
>> return render(request, 'formsub.html', {'form':
>> form_class,'x':a.userName.username,'id':a.id})
>> "
>> There is an error in the method also...
>> Console prints this whenever post request is made.
>> " [29/Sep/2017 18:43:43] "POST /login/update/18/ HTTP/1.1" 302 0
>> "
>>
> --
> 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/0e0dc653-92fe-4c3a-9cf5-e9d2de3cb274%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0e0dc653-92fe-4c3a-9cf5-e9d2de3cb274%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boXeKH%2B5GpKRJP1qQBoPOh9-Tgj7M93GZZKmgWOTh-x-fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: make a button element outside be on the right side of another element inside

2017-09-29 Thread Constantine Covtushenko
Dear Fabio,

Can you please provide html of your button here?

Thank you,

Regards,
Constantine C.

On Fri, Sep 29, 2017 at 8:37 AM, fábio andrews rocha marques <
fabioandrewsrochamarq...@gmail.com> wrote:

> unfortunally, it does trigger. I have an input and a button. The button is
> "?" and the input is my submit form button
>
> On Thursday, September 28, 2017 at 9:19:01 PM UTC-3, Vijay Khemlani wrote:
>>
>> An input with type "button" instead of "submit" should not trigger the
>> form submit.
>>
>> On Thu, Sep 28, 2017 at 7:56 PM, fábio andrews rocha marques <
>> fabioandrews...@gmail.com> wrote:
>>
>>> In my template, I have a form. This form has a lot of textfields and a
>>> submit button. There's another button, lets name it "?", that displays a
>>> popup window whenever it's clicked.
>>> I want the "?" button to be on the right side of one of the textfields
>>> on my form. The problem is: since the form has an action associated with
>>> it, if i put the button inside the form, whenever the user clicks on it,
>>> the system computes it's action as if the submit button was clicked too...
>>> I don't want this to happen.
>>>
>>> How can i position my "?" button to the right of a component which is
>>> inside a  even though my "?" button is outside the ?
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/ms
>>> gid/django-users/96716dc0-19d9-46e0-9c04-f0e644c57b8c%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/96716dc0-19d9-46e0-9c04-f0e644c57b8c%40googlegroups.com?utm_medium=email&utm_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/68b2dc94-8026-4bc9-b1f3-f636d76713b5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/68b2dc94-8026-4bc9-b1f3-f636d76713b5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boVwPx%2BXHgC%2BGDyn98T6PzVz95MxyWhuK4_xOp5sNJ8ycw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: get_ip_address() not working when used Custom Decorators

2017-09-29 Thread Constantine Covtushenko
Hi Mannu,

It seems like all are ok.
Sorry, but do you use it in just one place?
And do you see response in console from your print?

Regards,
Constantine C.

On Thu, Sep 28, 2017 at 4:36 PM, Mannu Gupta 
wrote:

> I am just using it in a view function. For example:-
>
> @owner_required
> def all(request, **kwargs):
> pass
>
>
> On Friday, September 29, 2017 at 12:33:09 AM UTC+5:30, Mannu Gupta wrote:
>>
>> While making a customer decorator in django, the code is here :-
>>
>> def owner_required(function):
>> def wrap(request, *args, **kwargs):
>> print(request)
>> ip_address = get_client_ip(request)
>> ip_exist = Node.objects.get(ip_address=ip_address)
>> if ip_exist:
>> return function(request, *args, **kwargs)
>> else:
>> raise PermissionDenied
>> return wrap
>>
>> my code for get_ip_address() is :-
>>
>> def get_client_ip(request):
>> """ Extract ip address from a Django request object
>> """
>> x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
>> if x_forwarded_for:
>> ip = x_forwarded_for.split(',')[0]
>> else:
>> ip = request.META.get('REMOTE_ADDR')
>> return ip
>>
>> The error i am getting is :-
>>
>> x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
>> AttributeError: 'function' object has no attribute 'META'
>>
>>
>> That get_client_ip() is working fine when used in normal function, but
>> don't know why it is not working when i am using it a decorator.
>>
>> What might be the problem ?
>>
>> Thanks in advance for replies.
>>
>> --
> 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/0e34ae73-5697-4a93-9402-c0ca1f4abd70%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0e34ae73-5697-4a93-9402-c0ca1f4abd70%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boWjKSfzbsLVOteF6shE_%3DYg%3DENx_AJhrvDXpSR%2BBzEDUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django: Form validation strange behaviour

2017-09-29 Thread Constantine Covtushenko
Hi Paul,

You should return value from 'clean_document'.
>From your code I see you do not do that. When method returns nothing it is
None.
That is why you see 'This field cannot be blank.'

I hope that make sense.

Regards,
Constantine C.

On Fri, Sep 29, 2017 at 7:01 AM, Paul  wrote:

> I want to do file validation(size,type) on a field on inlineformset.
>
>
> class ProductDocumentModelForm(ModelForm):
>
>   class Meta: model = ProductDocument
>fields = ['document']
>
>   def clean_document(self):
>file = self.cleaned_data['document']
>validate_file(file, 'document')
>
>
>
> Because I want to use the same validation in multiple application I
> created a separate function.
>
>
> def validate_file(file, for_model, max_size=5000):
>  if for_model == 'document':
>   max_size = FILE_MAX_DOC_SIZE
>
>  if file.size > max_size:
>   raise ValidationError('Please keep file size under {}. Current file size is 
> {}' .format(filesizeformat(FILE_MAX_DOC_SIZE), filesizeformat(file.size)))
>
>
>
> The file size validation works as intended but introduce a strange
> behavior.
>
>
> If this validation is in place and is passed the "This field cannot be
> blank." default validation is triggered even if the fields are not empty.
>
>
> Without the file size validation in place there are no issue even if the
> fields are empty.
>
>
> I don't understand what is the cause.
>
> --
> 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/a470e4e3-3cb9-489e-930c-8adc6b6210c3%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a470e4e3-3cb9-489e-930c-8adc6b6210c3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Updating an instance.

2017-09-30 Thread Constantine Covtushenko
Sounds good!

Have a great day

On Sat, Sep 30, 2017 at 1:45 AM, Mitul Tyagi  wrote:

> It is done.
> On Saturday, September 30, 2017 at 8:55:45 AM UTC+5:30, Mitul Tyagi wrote:
>>
>>
>> My form field is :
>>
>> class CityForm(forms.ModelForm):
>> class Meta:
>> model = City
>> fields = ['city1', 'city2', 'city3', 'city4', 'city5', 'userName']
>> widgets = {
>> 'city1': autocomplete.Select2(url='city-autocomplete'),
>> 'city2': autocomplete.Select2(url='city-autocomplete'),
>> 'city3': autocomplete.Select2(url='city-autocomplete'),
>>     'city4': autocomplete.Select2(url='city-autocomplete'),
>> 'city5': autocomplete.Select2(url='city-autocomplete'),
>> }
>>
>> On Saturday, September 30, 2017 at 7:41:40 AM UTC+5:30, Constantine
>> Covtushenko wrote:
>>>
>>> Dear Mitui,
>>>
>>> I saw 2 questions in your inquiry:
>>> 1. Regarding to Form behaviour
>>> 2. Regarding to log message
>>>
>>> Let me clarify second:
>>> Provided message said that server responded with 302 - redirect response.
>>> It is correct as you said in your view method:
>>> return HttpResponseRedirect('/login/response/'+str(a.userName.username))
>>>
>>> Now is about first.
>>> You printed 'using instance argument'. I asume that you are looking of
>>> a way add user info to POST data using form. It does not work in this way.
>>> That is why user info is cleared.
>>>
>>> Initial value is used to pre populate form when it is no POST data yet,
>>> like when you generate form on GET response.
>>>
>>> To get what you need I would suggest add user info differently.
>>> You have some options here.
>>>
>>> 1 - change your form - remove user field from it. You did not provide
>>> code of your form. But I believe that you are using user field in the form.
>>> 2 - add user info to POST query. It is not recommended way as this POST
>>> QuerySet is immutable. So to do that you need to create new QuerySet from
>>> previous one and put user info there.
>>>
>>> I hope that make some sense.
>>>
>>> Regards,
>>> Constantine C.
>>>
>>> On Fri, Sep 29, 2017 at 3:11 PM, Mitul Tyagi 
>>> wrote:
>>>
>>>> 
>>>> {% csrf_token %}
>>>> 
>>>> 1st City: {{form.city1}}
>>>> 2nd City: {{form.city2}}
>>>> 3rd City: {{form.city3}}
>>>> 4th City: {{form.city4}}
>>>> 5th City: {{form.city5}}
>>>>
>>>> 
>>>> Is the template part.
>>>>
>>>> On Saturday, September 30, 2017 at 12:16:07 AM UTC+5:30, Mitul Tyagi
>>>> wrote:
>>>>>
>>>>> Problem 1 :
>>>>> I have a model with  six fields. One is userName and other five are
>>>>> five favourite cities.I want to update these five citiesbut when I
>>>>> update them using instance argument the userName becomes NONEI am 
>>>>> using
>>>>> the id field to updatethe cities are updated for the id but the
>>>>> userName is lost. Any help for that..The code I am using is
>>>>> "
>>>>> def Update(request, city_id):
>>>>> if request.method == "POST":
>>>>> a= City.objects.get(pk= int(city_id))
>>>>> print "User Updated is : ",a.userName.username
>>>>>
>>>>> f = CityForm(request.POST, instance=a, initial={'userName.':
>>>>> str(a.userName.username)})
>>>>> f.save()
>>>>> return HttpResponseRedirect('/login/r
>>>>> esponse/'+str(a.userName.username))
>>>>> else:
>>>>> all_city = City.objects.all()
>>>>> for city in all_city:
>>>>> if int(city.pk) == int(city_id):
>>>>> a = city
>>>>> print "User: ",a.userName.username
>>>>> form_class = CityForm(initial={'userName': a.userName})
>>>>> return render(request, 'formsub.html', {'form':
>>>>> form_clas

Re: Add value to database without using forms in django

2017-09-30 Thread Constantine Covtushenko
Hi Mitul,

Can you clarify a little bit more your question?
What are you trying to resolve?
You asked: "How it will be done...?" It is not clear what exactly you are
trying to be done.

I guess that it my be saving cities into model 'cityval' fields. Am I
correct?

If so you can do something like that:

Name(cityval=''.join([city.city1, city.city2, ...])).save()

Regards,
Constantine C.

On Sat, Sep 30, 2017 at 5:39 AM, Mitul Tyagi  wrote:

> I have a model named "Name" which stores the list of all cities present in
> other model named  "City". How can it be done internally in the views.py
> without using forms. Here is the code of models.py
>
> "
> # -*- coding: utf-8 -*-
> from __future__ import unicode_literals
>
> from django.db import models
>
>
> class Detail(models.Model):
> username = models.CharField(max_length=100)
> password = models.CharField(max_length=100)
>
> def __str__(self):
> return str(self.username)
>
>
> class City(models.Model):
> userName = models.ForeignKey(Detail, blank=True, null=True)
> city1 = models.CharField(max_length=100)
> city2 = models.CharField(max_length=100)
> city3 = models.CharField(max_length=100)
> city4 = models.CharField(max_length=100)
> city5 = models.CharField(max_length=100)
> def __str__(self):
> return "Id No:" + str(self.pk)+" and Name: "+str(self.userName)
>
> class Name(models.Model):
> cityval=models.CharField(max_length=100)
> "
>
> --
> 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/5d83ea00-e613-4b86-830f-262b1db4ce99%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5d83ea00-e613-4b86-830f-262b1db4ce99%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boUvLwA4yELOr%3D%3DVqQJrT7G_n9-%3Dq%2Bqcutu%3DUrdDXf_GFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: get_ip_address() not working when used Custom Decorators

2017-10-01 Thread Constantine Covtushenko
Sorry for late response,

I meant that you might using that decorator in 2 places.
And asked about that.

It seems like you specified `@owner_required` to decorate your view
function. But that decorator behave like `@owner_required()`.

With your last response I see that decorated function instead of `request`
receives `function all`. It looks like improperly used decorator.

More than that I do not have more ideas from what you provided.


On Sat, Sep 30, 2017 at 4:02 PM, Mannu Gupta 
wrote:

> Hello Constantine C,
>
> Thanks for your reply!
>
> What do you mean to say just one place ?
> I just printed the request using `print(request)` and getting this
> `` ( don't know what this actually is )
>
> Am i using the following approach.
> On Saturday, September 30, 2017 at 8:08:22 AM UTC+5:30, Constantine
> Covtushenko wrote:
>>
>> Hi Mannu,
>>
>> It seems like all are ok.
>> Sorry, but do you use it in just one place?
>> And do you see response in console from your print?
>>
>> Regards,
>> Constantine C.
>>
>> On Thu, Sep 28, 2017 at 4:36 PM, Mannu Gupta 
>> wrote:
>>
>>> I am just using it in a view function. For example:-
>>>
>>> @owner_required
>>> def all(request, **kwargs):
>>> pass
>>>
>>>
>>> On Friday, September 29, 2017 at 12:33:09 AM UTC+5:30, Mannu Gupta wrote:
>>>>
>>>> While making a customer decorator in django, the code is here :-
>>>>
>>>> def owner_required(function):
>>>> def wrap(request, *args, **kwargs):
>>>> print(request)
>>>> ip_address = get_client_ip(request)
>>>> ip_exist = Node.objects.get(ip_address=ip_address)
>>>> if ip_exist:
>>>> return function(request, *args, **kwargs)
>>>> else:
>>>> raise PermissionDenied
>>>> return wrap
>>>>
>>>> my code for get_ip_address() is :-
>>>>
>>>> def get_client_ip(request):
>>>> """ Extract ip address from a Django request object
>>>> """
>>>> x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
>>>> if x_forwarded_for:
>>>> ip = x_forwarded_for.split(',')[0]
>>>> else:
>>>> ip = request.META.get('REMOTE_ADDR')
>>>> return ip
>>>>
>>>> The error i am getting is :-
>>>>
>>>> x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
>>>> AttributeError: 'function' object has no attribute 'META'
>>>>
>>>>
>>>> That get_client_ip() is working fine when used in normal function, but
>>>> don't know why it is not working when i am using it a decorator.
>>>>
>>>> What might be the problem ?
>>>>
>>>> Thanks in advance for replies.
>>>>
>>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/ms
>>> gid/django-users/0e34ae73-5697-4a93-9402-c0ca1f4abd70%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/0e34ae73-5697-4a93-9402-c0ca1f4abd70%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Sincerely yours,
>> Constantine C
>>
> --
> 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/69879830-d7ad-4914-a8d4-7ac1ba1d8241%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/69879830-d7ad-4914-a8d4-7ac1ba1d8241%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Django and Oracle 10g

2017-10-07 Thread Constantine Covtushenko
Hi Paulo,

Did you read
https://docs.djangoproject.com/en/1.11/ref/databases/#oracle-notes?

I did not use oracle backend in any of my projects.
But with Django ORM one will never depend on DB type in common scenarios.

I hope that helps.

Regards,
Constantine C.

On Sat, Oct 7, 2017 at 8:51 PM,  wrote:

> I'm new Here. I'm know Java and C#. I know php with laravel framework.
> But in Python I'm starting.
> I need to connect Python with my oracle 10g database, and with the
> cx_Oracle driver everything worked out.
> But I do not know how to use this cx_Oracle driver in Django's frameWork.
> Would someone please have an example to help. How do I proceed?
>
> Paulo
>
> --
> 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/27ea0565-87d2-4dd6-883a-2b479fbfc390%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/27ea0565-87d2-4dd6-883a-2b479fbfc390%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: How do I do a multiple select in the Admin filters ?

2016-07-25 Thread Constantine Covtushenko
Hi Hurlu,

I can suggest two approaches here.

   1. change your model so that it contains two fields: 'allowed' and 
   'disallowed'. Every of which is an array of allowed and disallowed items 
   respectively. You can use JSON Field for that. This approach has benefit 
   that your models looks simple and can be easily extended with additional 
   allowed/disallowed items. In your example every time new valuable property 
   identified your should extend model and handle migrations both schema and 
   data. With this approach Django/admin can handle your 
   requirements pretty straightforward.
   2.  create custom form with 2 custom fields: allowed and disallowed. 
   Exclude all extra filters as an 'excluded'. And override 'save' method to 
   map users data from use input to model filters. And do it before model is 
   saved.

I hope that should solve your problem.
Regards

On Monday, July 25, 2016 at 6:25:29 PM UTC+3, Hurlu wrote:
>
> Hi everyone,
>
> For the project I'm working on, I got a Dish Model in which, in order to 
> filter different dishes for allergens or other reasons, I got a 
> BooleanField to check if the dish is* pork-free*, another to check if it's* 
> nuts-free* and a good other 
>
> *dozen.*As you would expect, displaying all thoses filters side by side 
> would by very unesthetical and unpratical. So I aimed to reduce their 
> number to two: One *multiple select* filter for "*contains this:*", and 
> another for "*does not contain*:".
>
> My researches so far were not very successful : the best I could find is 
> this module , namely Django-adminfilters 
> ,
>  
> that I could not quite get to work, as well as many not-so-helpful SO 
> posts. 
> 
> 
> Could someone please enlighten me, be it with a way to do it or a 
> workaround ?
> Thanks a lot !
>

-- 
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/9184f12b-1d1d-4630-9f5a-a2ab74980726%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django MySql weirdness

2016-07-25 Thread Constantine Covtushenko
Hi Steve,

Can you please provide code snippet here for 'action_time' field?

Regards,

On Mon, Jul 25, 2016 at 9:11 PM, Steve Bischoff 
wrote:

>
>
> http://stackoverflow.com/questions/38534734/django-42000-invalid-default-value-for-action-time
>
> I have been trying to figure this one out for a bit now, does anyone have
> any tips on why mysql won't take in this date time from django?
>
> Thanks
>
> --
> 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/e7900617-6c13-4bbc-b9ad-a542310d79a8%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boWEQ%3DebdOriaSBziy-TqLZGN3%2BTeSWZWbmBvEdcK3V4Pw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Any way to force Django to commit a write so another process can read the correct data from DB?

2016-07-27 Thread Constantine Covtushenko
Hi Stodge,

As said in Django current version of documentation
,
'post_delete' signal is sent after record is deleted. This means also that
transaction is closed at that moment. And DB should not has deleted
instance any more.

I have double checked the Django code and can say that Django send that
signal just before transaction is committed.
So technically instance should be inside DB for Hibernate processing.

I can suggest you to create a custom signal and send it after transaction
closed.
That should solve your problem.

Regards,

On Wed, Jul 27, 2016 at 5:27 PM, Stodge  wrote:

> My website uses a combination of Django + Java apps to function. For this
> particular problem, a record is deleted from the DB via a TastyPie resource
> DELETE operation. A Django signal post_delete handleris invoked, which
> submits a DELETE request to Jetty running in the Java app. The Java app
> then performs a query using Hibernate.
>
> What appears to be happening is that Django thinks the record was deleted:
>
> DynamicVolume.objects.filter(user=instance.user).count()
>
> Returns ZERO.
>
> However, the Java app thinks the record still exists unless I make it
> sleep for several seconds before asking Hibernate to query the DB.
>
> I've tried forcing Hibernate to clear its cache with no success. Is there
> a way to force Django to commit the deletion (flush the cache)?
>
> Thanks
>
> --
> 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/e76d5cfa-f4bc-41db-a322-0d44aa0719dd%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boWeFYGOhk0CL%2BoEimreb2k%2BgFwL2rBb0imoPbmfpwo5Yw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to add logo to django header

2016-07-28 Thread Constantine Covtushenko
Hi Gauri,

One of approach is would be to override admin base template used as a
parent for all admin pages.
Please see that documentation link

about how to do that.

Regards,

On Thu, Jul 28, 2016 at 9:04 AM, Gauri Shirsath <
gauri.shirs...@inspiritvision.com> wrote:

> Hi,
>
> I want to show company logo instead of 'Django Administrator' heading.
> Can someone please guide me.
>
> Regards,
> Gauri
>
> --
> 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/991a1cf4-8a32-4941-ae43-e7a3f46916af%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boWCWBDXyFJ%3D1SvJhbAjKPgrY6w3N2_GkDBfO5X%3D-xd_VA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Any way to force Django to commit a write so another process can read the correct data from DB?

2016-07-28 Thread Constantine Covtushenko
Hi Mike,

It is not a bug.
It is just how it works.

Regards

On Thu, Jul 28, 2016 at 3:53 AM, Mike Dewhirst 
wrote:

> On 28/07/2016 5:46 AM, Constantine Covtushenko wrote:
>
>> Hi Stodge,
>>
>> As said in Django current version of documentation
>> <https://docs.djangoproject.com/en/1.9/ref/signals/#post-delete>,
>> 'post_delete' signal is sent after record is deleted. This means also
>> that transaction is closed at that moment. And DB should not has deleted
>> instance any more.
>>
>> I have double checked the Django code and can say that Django send that
>> signal just before transaction is committed.
>>
>
> Is this a Django bug?
>
> Is it the same for post_save?
>
> Mike
>
> So technically instance should be inside DB for Hibernate processing.
>>
>> I can suggest you to create a custom signal and send it after
>> transaction closed.
>> That should solve your problem.
>>
>> Regards,
>>
>> On Wed, Jul 27, 2016 at 5:27 PM, Stodge > <mailto:sto...@gmail.com>> wrote:
>>
>> My website uses a combination of Django + Java apps to function. For
>> this particular problem, a record is deleted from the DB via a
>> TastyPie resource DELETE operation. A Django signal post_delete
>> handleris invoked, which submits a DELETE request to Jetty running
>> in the Java app. The Java app then performs a query using Hibernate.
>>
>> What appears to be happening is that Django thinks the record was
>> deleted:
>>
>> DynamicVolume.objects.filter(user=instance.user).count()
>>
>> Returns ZERO.
>>
>> However, the Java app thinks the record still exists unless I make
>> it sleep for several seconds before asking Hibernate to query the DB.
>>
>> I've tried forcing Hibernate to clear its cache with no success. Is
>> there a way to force Django to commit the deletion (flush the cache)?
>>
>> Thanks
>>
>> --
>> 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/e76d5cfa-f4bc-41db-a322-0d44aa0719dd%40googlegroups.com
>> <
>> https://groups.google.com/d/msgid/django-users/e76d5cfa-f4bc-41db-a322-0d44aa0719dd%40googlegroups.com?utm_medium=email&utm_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
>> <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/CAK52boWeFYGOhk0CL%2BoEimreb2k%2BgFwL2rBb0imoPbmfpwo5Yw%40mail.gmail.com
>> <
>> https://groups.google.com/d/msgid/django-users/CAK52boWeFYGOhk0CL%2BoEimreb2k%2BgFwL2rBb0imoPbmfpwo5Yw%40mail.gmail.com?utm_medium=email&utm_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/450c40f7-8997-6669-b307-b39825d00adb%40dewhirst.com.au
> .
>
> 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/CAK52boUd%3D1-QiYBhA-284%3D-J-VZCiGKcnsmRs9Kpk%2BYtaff8ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query annotation with date difference

2016-07-31 Thread Constantine Covtushenko
Hi Yoann,

I am not sure exactly but believes you are on the right way.
Try improve your expression with ExpressionWrapper, as said here

.
Probably the problem is that you use values of different types in your
expression.

Regards

On Sat, Jul 30, 2016 at 11:35 PM, Yoann Duriaud 
wrote:

> Hello,
> I would like to annotate a query with the following expression: ([Due
> Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the
> database, while [Now] should be "equal" to timezone.now().
>
> So this would look like:
> .annotate(ratio=(F('due_date')-timezone.now())/F('Interval'))
>
> but this does not work. Does someone know how the expression should be
> written (if it is indeed feasible with Django ORM)?
>
> Thanks for your help!
>
> Yoann
>
> --
> 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/03dedd39-142f-468a-b6fd-b7ec551862e8%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boX7irnk5X8GjUACuHCTDjzHpjHvpmP0O_fbUfhJZDAP6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Search multiple fields in Django Models

2016-08-01 Thread Constantine Covtushenko
Hi Jurgens,

Django is the right choice.
With Django all are possible.

All that you described are possible. If you need more precise answer give
us more precise question.

Regards,

On Mon, Aug 1, 2016 at 4:21 PM, Jurgens de Bruin 
wrote:

> Hi,
>
> I am new to Django, I have been using TurboGears for the last few years. I
> would like to help with regards to a multi search function.
>
> In essence I would like 1 search field/form that will search multiple
> fields of different datatype example user should be able to search the
> model/db for either an ID(interger),Name(Text/Char),Date Captured(date
> time). Secondely my models in split in classes each class representing a
> database table I have setup forgein keys within the Model Classes to the
> relation tables. The search should also search all the tables/model.
>
> Is this possible?
>
> Thank in advance.
>
> --
> 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/65c0df55-dfb1-49eb-a6ed-838e9e7b420a%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boWOtRV5YsGz5D1oVH0b-j50zg3TPk5X07CbnAmbdUwtxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query annotation with date difference

2016-08-01 Thread Constantine Covtushenko
Hi,

I am not cleat of what you suggested as a dictionary method and how you are
going to use it.

But any way let me check my guesses and I will be back.

On Mon, Aug 1, 2016 at 11:25 PM, Yoann Duriaud 
wrote:

> Thanks for the tip, but besides defining the type of the output it is
> unclear how this can be used to perform a date difference operation.
>
> What I would need is to convert *timezone.now()* into a date constant
> that can be understood by the database, whatever the database is. If I
> leave it as it is, I get the str() conversion, which is meaningless for the
> database. Even if I find some format *dd-mm-* that works with a given
> database, I wouldn't be sure that it works with other databases. I need the
> ORM to perform the conversion *Date Object -> Database date constant*.
>
> Then comes the date difference operation. Same thing: either the database
> understands the minus sign with date format, or it doesn't and need some
> DATEDIFF operator. Again I would need the ORM to explicitly set the right
> operator.
> My guess at the moment is that this cannot be achieved with Django ORM. I
> may apply the dict method and work with the dictionary instead, so that I
> can add custom fields more easily.
>
> Yoann
>
>
>
> Le dimanche 31 juillet 2016 09:25:58 UTC+2, Constantine Covtushenko a
> écrit :
>>
>> Hi Yoann,
>>
>> I am not sure exactly but believes you are on the right way.
>> Try improve your expression with ExpressionWrapper, as said here
>> <https://docs.djangoproject.com/en/1.9/ref/models/expressions/#using-f-with-annotations>
>> .
>> Probably the problem is that you use values of different types in your
>> expression.
>>
>> Regards
>>
>> On Sat, Jul 30, 2016 at 11:35 PM, Yoann Duriaud 
>> wrote:
>>
>>> Hello,
>>> I would like to annotate a query with the following expression: ([Due
>>> Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the
>>> database, while [Now] should be "equal" to timezone.now().
>>>
>>> So this would look like:
>>> .annotate(ratio=(F('due_date')-timezone.now())/F('Interval'))
>>>
>>> but this does not work. Does someone know how the expression should be
>>> written (if it is indeed feasible with Django ORM)?
>>>
>>> Thanks for your help!
>>>
>>> Yoann
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/03dedd39-142f-468a-b6fd-b7ec551862e8%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/03dedd39-142f-468a-b6fd-b7ec551862e8%40googlegroups.com?utm_medium=email&utm_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/60119a06-5b1f-4e23-a142-627c65f14017%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/60119a06-5b1f-4e23-a142-627c65f14017%40googlegroups.com?utm_medium=email&utm_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/CAK52boXEZ%2BygOsiaE%3DZf5TbDMLLyixR--keV6jXXCKJPC_3w4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: cookiecutter-django installation

2016-08-01 Thread Constantine Covtushenko
Hi Gary,

It is not clear what errors you have gotten.
Can you please describe them?

I am not using Eclipse any more so can not reproduce you problem by my own.
But all should be run without problem

On Mon, Aug 1, 2016 at 11:14 PM, Gary Roach 
wrote:

> I am having trouble with a cookiecutter-django installation. I don't have
> a normal virtualenv setup because I use Eclipse IDE with PyDev plugin. This
> means that all of the project files are outside of the virtualenv wrapper
> and vrtualenv is never actually activated. My OS is Debian Linux with KDE
> desktop. I have my virtualenv files in the
> /opt/python-virtual-environments/ directory. Eclipse requires me to work
> out of a workspace directory which is at /home/gary/workspace. I then point
> Eclipse at the /opt/python-virtual-environments/ directory for the proper
> versions of python and django.
>
> I can't figure out how to use cookiecutter-django with the above
> installation. Could anyone that uses PyDev give me some advice or point me
> to some more pertinent documentation for the installation.
>
> Gary R.
>
> --
> 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/62479cd9-99aa-ca5e-1d67-0872549e7c5f%40verizon.net
> .
> 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/CAK52boUUJRk2AmzL98ExkbiTdfUSaBYGLGY1hzf5_3%3DW6mhWvQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query annotation with date difference

2016-08-02 Thread Constantine Covtushenko
Ok, I am ready.

I did exactly as I suggested and got *successful* result.
Please check screenshots below:
on admin:
[image: Inline image 1]
on table view with annotated field:
[image: Inline image 2]

were
-model

class Entity(models.Model):
due_date = models.DateTimeField(default=timezone.now())
interval = models.PositiveSmallIntegerField(default=2)

objects = EntityManager()


and manager

class EntityManager(models.Manager):
def get_items(self):
return self.all().annotate(
ratio=models.ExpressionWrapper(
(models.F('due_date') -
timezone.now())/models.F('interval'), models.DateTimeField()))

As we can see no dates format problem at all.
Django works as expected - perfectly!

Hope that helps.

Regards,


On Tue, Aug 2, 2016 at 8:35 AM, Constantine Covtushenko <
constantine.covtushe...@gmail.com> wrote:

> Hi,
>
> I am not cleat of what you suggested as a dictionary method and how you
> are going to use it.
>
> But any way let me check my guesses and I will be back.
>
> On Mon, Aug 1, 2016 at 11:25 PM, Yoann Duriaud 
> wrote:
>
>> Thanks for the tip, but besides defining the type of the output it is
>> unclear how this can be used to perform a date difference operation.
>>
>> What I would need is to convert *timezone.now()* into a date constant
>> that can be understood by the database, whatever the database is. If I
>> leave it as it is, I get the str() conversion, which is meaningless for the
>> database. Even if I find some format *dd-mm-* that works with a
>> given database, I wouldn't be sure that it works with other databases. I
>> need the ORM to perform the conversion *Date Object -> Database date
>> constant*.
>>
>> Then comes the date difference operation. Same thing: either the database
>> understands the minus sign with date format, or it doesn't and need some
>> DATEDIFF operator. Again I would need the ORM to explicitly set the right
>> operator.
>> My guess at the moment is that this cannot be achieved with Django ORM. I
>> may apply the dict method and work with the dictionary instead, so that I
>> can add custom fields more easily.
>>
>> Yoann
>>
>>
>>
>> Le dimanche 31 juillet 2016 09:25:58 UTC+2, Constantine Covtushenko a
>> écrit :
>>>
>>> Hi Yoann,
>>>
>>> I am not sure exactly but believes you are on the right way.
>>> Try improve your expression with ExpressionWrapper, as said here
>>> <https://docs.djangoproject.com/en/1.9/ref/models/expressions/#using-f-with-annotations>
>>> .
>>> Probably the problem is that you use values of different types in your
>>> expression.
>>>
>>> Regards
>>>
>>> On Sat, Jul 30, 2016 at 11:35 PM, Yoann Duriaud 
>>> wrote:
>>>
>>>> Hello,
>>>> I would like to annotate a query with the following expression: ([Due
>>>> Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the
>>>> database, while [Now] should be "equal" to timezone.now().
>>>>
>>>> So this would look like:
>>>> .annotate(ratio=(F('due_date')-timezone.now())/F('Interval'))
>>>>
>>>> but this does not work. Does someone know how the expression should be
>>>> written (if it is indeed feasible with Django ORM)?
>>>>
>>>> Thanks for your help!
>>>>
>>>> Yoann
>>>>
>>>> --
>>>> 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...@googlegroups.com.
>>>> To post to this group, send email to django...@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/03dedd39-142f-468a-b6fd-b7ec551862e8%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/03dedd39-142f-468a-b6fd-b7ec551862e8%40googlegroups.com?utm_medium=email&utm_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

Re: cookiecutter-django installation

2016-08-02 Thread Constantine Covtushenko
Hi Garry,

It seems like your question is out of scope of django-users group topic.

You can address it to some other community, say on http://stackoverflow.com/
.

I will be ready to respond you there.

Regards,



On Tue, Aug 2, 2016 at 9:41 PM, Gary Roach 
wrote:

> On 08/01/2016 10:39 PM, Constantine Covtushenko wrote:
> Hi Constantine
>
> I guess I didn't make my self clear. I have not installed
> cookiecutter-debian because I haven't figured out how to do that with my
> setup. There are no errors because there is no installation.,
>
> Gary Rl
>
> Hi Gary,
>
> It is not clear what errors you have gotten.
> Can you please describe them?
>
> I am not using Eclipse any more so can not reproduce you problem by my own.
> But all should be run without problem
>
> On Mon, Aug 1, 2016 at 11:14 PM, Gary Roach 
> wrote:
>
>> I am having trouble with a cookiecutter-django installation. I don't have
>> a normal virtualenv setup because I use Eclipse IDE with PyDev plugin. This
>> means that all of the project files are outside of the virtualenv wrapper
>> and vrtualenv is never actually activated. My OS is Debian Linux with KDE
>> desktop. I have my virtualenv files in the
>> /opt/python-virtual-environments/ directory. Eclipse requires me to work
>> out of a workspace directory which is at /home/gary/workspace. I then point
>> Eclipse at the /opt/python-virtual-environments/ directory for the proper
>> versions of python and django.
>>
>> I can't figure out how to use cookiecutter-django with the above
>> installation. Could anyone that uses PyDev give me some advice or point me
>> to some more pertinent documentation for the installation.
>>
>> Gary R.
>>
>> --
>> 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/62479cd9-99aa-ca5e-1d67-0872549e7c5f%40verizon.net>
>> https://groups.google.com/d/msgid/django-users/62479cd9-99aa-ca5e-1d67-0872549e7c5f%40verizon.net
>> .
>> 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/CAK52boUUJRk2AmzL98ExkbiTdfUSaBYGLGY1hzf5_3%3DW6mhWvQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> https://groups.google.com/d/msgid/django-users/CAK52boUUJRk2AmzL98ExkbiTdfUSaBYGLGY1hzf5_3%3DW6mhWvQ%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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a97caed8-4a20-1e26-e9a2-441d726bb249%40verizon.net
> <https://groups.google.com/d/msgid/django-users/a97caed8-4a20-1e26-e9a2-441d726bb249%40verizon.net?utm_medium=email&utm_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/CAK52boUadF6ZH%2BfHM13wxn6xsviqhRZuYUz8WqfrwY_HJXiL7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing session in Django models?

2016-08-03 Thread Constantine Covtushenko
Hi Neto,

As said in Documentation of 'limit_choices_to'

value for this key should be:
`Either a dictionary, a Q object, or a callable returning a dictionary or Q
object can be used.`

For your case these mean that you should use at least callable as 'use__id'
should be defined every Request/Response cycle.

Regards,


On Wed, Aug 3, 2016 at 7:25 PM, Neto  wrote:

> I have a field with *limit_choices_to*, and want it to be only filtered
> items related the account ('ID') user. How can I do this?
>
> Example (Does not work):
>
> class Car(models.Model):
> user = models.ForeignKey(User)
> color = models.CharField(max_length=200)
> typeo = models.ForeignKey(Typeo, limit_choices_to={'user__id': 
> session['user_id']})
>
> --
> 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/8d2b4b10-83b9-489c-b834-31ddebc0c9df%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXQ3T1Hb-OodKYLR%3DT66JDW76H_sBuRY0A33etJS-JFnw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do templates automatically convert dates to local timezone?

2016-08-03 Thread Constantine Covtushenko
Hi Robert,

You have touched a very simple but always confusing questions - storing
dates and showing them to users in different places.

As I know Django uses that in very straightforward way.
It always converts dates to UTC.
Flow that converts them back to different users in different time-zones is
adjusted through settings.

Please check settings for your testing environment.
More information you can find on that `i18` documentation page
.

Regards,
I hope that helps.


On Wed, Aug 3, 2016 at 11:36 PM, Robert Rollins 
wrote:

> I'm writing tests that assert dates are being properly rendered on a
> certain page, but the tests are failing because the date value on the model
> object is in UTC, and the date is rendered in local time on the template.
> I'd like to run that date value through the same mechanism by which the
> template converts it to local time, so that my test does the same thing as
> the template.
>
> I've looked around, and unfortunately been unable to find the code that
> does the automatic conversion. The "date" template filter doesn't do it,
> and I'm too ignorant of the nitty gritty details of django template system
> to know what else I should be looking for.
>
> Any help would be appreciated.
>
> --
> 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/b4f5a0d6-8aea-47a9-969e-45c7a407a104%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boUGjOWLZfF3big60Ps1Ra%3DxjsZGMMy%3DTZ98Az2wMHhucg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query annotation with date difference

2016-08-03 Thread Constantine Covtushenko
Sorry, I did not specify.
I have been using 'Postgresql' with 'psycopg2 v.2.6.2'.
They gave me those results.

Also here is a sql query given from log:
SELECT "test_app_entity"."id", "test_app_entity"."due_date",
"test_app_entity"."interval", (("test_app_entity"."due_date" -
'2016-08-03T21:31:58.325549+00:00'::timestamptz) /
"test_app_entity"."interval") AS "ratio" FROM "test_app_entity";
args=(datetime.datetime(2016, 8, 3, 21, 31, 58, 325549, tzinfo=),)

That is all that I can say at the moment.

On Thu, Aug 4, 2016 at 12:20 AM, Yoann Duriaud 
wrote:

> Thanks, unfortunately not so great on my side:
>
> I added in the query (forgetting the division for now):
>
> .annotate(ratio=ExpressionWrapper(F('due_date')-timezone.now(),
> DateTimeField()))
>
>
> which leads to the following statement in the query:
>
> ("contentstatus"."due_date" - 2016-08-03 21:05:10.743799+00:00) AS "ratio"
>
>
> This is not a valid SQL statement (at least for SQLite) and leads to the
> following error message when the query is evaluated:
>
> Exception Type:
>
> TypeError
> Exception Value:
>
>
> expected string or bytes-like object
>
>
> Any idea what I get this behavior?
>
> Yoann
>
>
> Le samedi 30 juillet 2016 22:41:21 UTC+2, Yoann Duriaud a écrit :
>>
>> Hello,
>> I would like to annotate a query with the following expression: ([Due
>> Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the
>> database, while [Now] should be "equal" to timezone.now().
>>
>> So this would look like:
>> .annotate(ratio=(F('due_date')-timezone.now())/F('Interval'))
>>
>> but this does not work. Does someone know how the expression should be
>> written (if it is indeed feasible with Django ORM)?
>>
>> Thanks for your help!
>>
>> Yoann
>>
> --
> 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/038837c5-6b5b-4ae9-895a-b6b54282d978%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boX3b%2Bb6okqsKVXX%3DxQ7HUss9qL_BRbL8rpWFGE%3Ds2xL9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: QuerySet for related models

2016-08-04 Thread Constantine Covtushenko
Hi M Hashmi,

As I see your model scheme built with meaning that 1 record of HitCount
relates to many records of Product.
And in your queries you try to select all products that relate to 5 topmost
HitCounts.

Am I correct?

Will be waiting for your response.


On Thu, Aug 4, 2016 at 6:41 PM, M Hashmi  wrote:

> I know that count only can be applied for an IntegerField or FloatField
> but I've created a ForeignKey to another model which contains hitcounts.
> Now I need to filter results by max count from related model and I couldn't
> dot it.
>
>
> models.py:
>
>
> class Product(models.Model):
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
> active = models.BooleanField(default=True)
> categories = models.ManyToManyField('Category', blank=True)
> default = models.ForeignKey('Category', related_name='default_category', 
> null=True, blank=True)
> hits = models.ForeignKey(HitCount)
>
> objects = ProductManager()
>
> class Meta:
> ordering = ["-title", '-hits']
>
>
> The idea is to access Hitcount field hits to count max value and sort
>  list by max count. Below is Hitcount model installed as third party
> reusable app djagno-hitcount.
>
>  HitCount(models.Model):
> hits = models.PositiveIntegerField(default=0)
> modified = models.DateTimeField(auto_now=True)
> content_type = models.ForeignKey(ContentType, 
> related_name="content_type_set_for_%(class)s", on_delete=models.CASCADE)
> object_pk = models.PositiveIntegerField('object ID')
> content_object = GenericForeignKey('content_type', 'object_pk')
>
> objects = HitCountManager()
>
> class Meta:
> ordering = ('-hits',)
> get_latest_by = "modified"
> verbose_name = _("hit count")
> verbose_name_plural = _("hit counts")
> unique_together = ("content_type", "object_pk")
> db_table = "hitcount_hit_count"
>
>
> I need to call products in multiple apps with different list and in
> my mainpage views I am trying to use filter option like below:
>
> from django.db.models import Max, Sum, Count
> product1 = Product.objects.all().annotate(hits=Count('-hits__hits'))[:6]
>
> or
>
> product1 = Product.objects.all().order_by('-hits__hits')[:6]
>
> and with few different filter options. I couldn't make it work so advise
> would be appreciated.
>
> --
> 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/39e610bf-0558-4a8d-8491-f9324d8986f1%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXyqDJMFndLHALhrXnpV5%3Dj-mH8xiX45XJkw0F7HR9Srg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: QuerySet for related models

2016-08-04 Thread Constantine Covtushenko
Please check my notes below:

On Thu, Aug 4, 2016 at 10:42 PM, M Hashmi  wrote:

> My field hits=models.ForeignKey(Hitcount) means that my Product model has
> a related  model with multiple fields and all the products in Product model
> will have one or more hit records.
>
Sorry but I do not see how Product model will have many hit records.
May be you should change it on:

hits = models.ManyToMany(Hitcount)



> Instance of Product model will save a hit from end user by session/ip/user
> etc.
>
> --
> 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/81557c06-29ac-44d0-b76c-b3fea37c83f2%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXSLH1E9CA0cAF6gJp0LowWs3Znj%2BQXEC12_6HFXkwedQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: QuerySet for related models

2016-08-04 Thread Constantine Covtushenko
Hi M Hashmi,

I believe that you are looking a way to use aggregation on related model.
You should try the following snitppet:
`trending_products = Product.objects.aggregate(hit=Max('hits__hits'))[:6]`
(see more info here
)

This will give you list of products where each product will have 'hit' is
the MAX value of all hits set for this product.

Also I do not see any reason to use 'ContentType' relation from your
HitCount model at all.
If your origin intent was to have hits with any Model in your
system(project) then you should built 'joins with aggregation' queries
based on Reverse Generic Relation as said Todor. But in this case Product
hits field becomes unnecessary as it duplicates relations.

On Fri, Aug 5, 2016 at 5:59 AM, M Hashmi  wrote:

> Hello Todor,
>
> I followed your directions and used
> https://docs.djangoproject.com/ja/1.9/ref/contrib/contenttypes/ for
> reference but I got stuck at error 'GenericForeignKey' object has not
> attribute 'get_lookup'. I tried
> Product.objects.aggregate(Count('hits'))[:6]. In my models.py I got
> following code:
>
> hits = GenericRelation(HitCount, content_type_field='content_object',
> object_id_field='object_pk',)
>
> class Meta:
> ordering = ["-title"]
> Removed the -hits from ordering section and rest of the code is same. I
> searched it on google but it showed some Django based bugs.
> Any suggestions?
> Thanks,
>
>
>
> On Thursday, August 4, 2016 at 2:07:53 PM UTC-7, Todor Velichkov wrote:
>>
>> My field hits=models.ForeignKey(Hitcount) means that my Product model has
>>> a related  model with multiple fields and all the products in Product model
>>> will have one or more hit records. Instance of Product model will save a
>>> hit from end user by session/ip/user etc.
>>
>> Honestly, I don't understand that.
>>
>> The HitCount class already has a GenericForeignKey, maybe you are
>> looking for a Reverse Generic Relation
>> 
>> class in order to get the Hits for a product.
>>
>> On Thursday, August 4, 2016 at 10:42:58 PM UTC+3, M Hashmi wrote:
>>>
>>> My field hits=models.ForeignKey(Hitcount) means that my Product model
>>> has a related  model with multiple fields and all the products in Product
>>> model will have one or more hit records. Instance of Product model will
>>> save a hit from end user by session/ip/user etc.
>>>
>> --
> 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/2a7be23a-c227-460d-89f2-d7ffd52d4123%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXEMAx6ihuMaBDE_we3UQ7sPuizhe3WeGqaTsJSXyLKpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: AttributeError overriding save_existing_objects in Formset class

2016-08-09 Thread Constantine Covtushenko
Hi Vincenzo,

Can you please specify Django version that you are using.

Regards,

On Tue, Aug 9, 2016 at 6:06 PM, Vincenzo  wrote:

> Hi there,
> I'm using the admin and I have a form admin  and an inline admin form. For
> this inline admin, I need to ignore modifications done for existing items:
> for this task I have done an override of save_existing_objects method for a
> Formset which inherit from forms.models.BaseInlineFormset. In this
> function I simply call the super with commit=False but doing that cause the
> following error:
>
> traceback (most recent call last):
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/core/handlers/base.py", line 149, in get_response
> response = self.process_exception_by_middleware(e, request)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/core/handlers/base.py", line 147, in get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs
> )
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/contrib/admin/options.py", line 541, in wrapper
> return self.admin_site.admin_view(view)(*args, **kwargs)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/utils/decorators.py", line 149, in _wrapped_view
> response = view_func(request, *args, **kwargs)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
> response = view_func(request, *args, **kwargs)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/contrib/admin/sites.py", line 244, in inner
> return view(request, *args, **kwargs)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/reversion/admin.py", line 186, in change_view
> return super(VersionAdmin, self).change_view(request, object_id,
> form_url, extra_context)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/contrib/admin/options.py", line 1440, in change_view
> return self.changeform_view(request, object_id, form_url,
> extra_context)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/utils/decorators.py", line 67, in _wrapper
> return bound_func(*args, **kwargs)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/utils/decorators.py", line 149, in _wrapped_view
> response = view_func(request, *args, **kwargs)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/utils/decorators.py", line 63, in bound_func
> return func.__get__(self, type(self))(*args2, **kwargs2)
>   File "/usr/lib/python3.4/contextlib.py", line 30, in inner
> return func(*args, **kwds)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/contrib/admin/options.py", line 1379, in changeform_view
> self.save_related(request, form, formsets, not add)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/contrib/admin/options.py", line 1015, in save_related
> self.save_formset(request, form, formset, change=change)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/contrib/admin/options.py", line 1003, in save_formset
> formset.save()
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/forms/models.py", line 645, in save
> return self.save_existing_objects(commit) + self.save_new_objects(
> commit)
>   File "/home/vincenzo/workspace/mynetgest2/warehouse/forms.py", line 118,
> in save_existing_objects
> instances_not_saved = super(IncomingBillOfLadingRowFormset, self).
> save_existing_objects(commit=False)
>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
> packages/django/forms/models.py", line 763, in save_existing_objects
> self.saved_forms.append(form)
> AttributeError: 'IncomingBillOfLadingRowFormFormSet' object has no
> attribute 'saved_forms'
>
> Is there something I'm doing wrong?
>
> --
> 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/cc82fa71-3edb-49f7-b46b-c1f043eafd2a%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django u

Re: AttributeError overriding save_existing_objects in Formset class

2016-08-10 Thread Constantine Covtushenko
I believe that you should also override `save` method with your
commit=False.

That `save` method and `save_existing_objects` method works in sync. It is
supposed that they should have the same `commit` value.

Hope that helps,

On Wed, Aug 10, 2016 at 10:14 AM, Vincenzo  wrote:

> The Django version I'm using is the 1.9.4
>
> Il giorno martedì 9 agosto 2016 22:04:57 UTC+2, Constantine Covtushenko ha
> scritto:
>>
>> Hi Vincenzo,
>>
>> Can you please specify Django version that you are using.
>>
>> Regards,
>>
>> On Tue, Aug 9, 2016 at 6:06 PM, Vincenzo  wrote:
>>
>>> Hi there,
>>> I'm using the admin and I have a form admin  and an inline admin form.
>>> For this inline admin, I need to ignore modifications done for existing
>>> items: for this task I have done an override of save_existing_objects
>>> method for a Formset which inherit from forms.models.BaseInlineFormset.
>>> In this function I simply call the super with commit=False but doing that
>>> cause the following error:
>>>
>>> traceback (most recent call last):
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/core/handlers/base.py", line 149, in get_response
>>> response = self.process_exception_by_middleware(e, request)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/core/handlers/base.py", line 147, in get_response
>>> response = wrapped_callback(request, *callback_args, **
>>> callback_kwargs)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/contrib/admin/options.py", line 541, in wrapper
>>> return self.admin_site.admin_view(view)(*args, **kwargs)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/utils/decorators.py", line 149, in _wrapped_view
>>> response = view_func(request, *args, **kwargs)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/views/decorators/cache.py", line 57, in
>>> _wrapped_view_func
>>> response = view_func(request, *args, **kwargs)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/contrib/admin/sites.py", line 244, in inner
>>> return view(request, *args, **kwargs)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/reversion/admin.py", line 186, in change_view
>>> return super(VersionAdmin, self).change_view(request, object_id,
>>> form_url, extra_context)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/contrib/admin/options.py", line 1440, in change_view
>>> return self.changeform_view(request, object_id, form_url,
>>> extra_context)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/utils/decorators.py", line 67, in _wrapper
>>> return bound_func(*args, **kwargs)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/utils/decorators.py", line 149, in _wrapped_view
>>> response = view_func(request, *args, **kwargs)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/utils/decorators.py", line 63, in bound_func
>>> return func.__get__(self, type(self))(*args2, **kwargs2)
>>>   File "/usr/lib/python3.4/contextlib.py", line 30, in inner
>>> return func(*args, **kwds)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/contrib/admin/options.py", line 1379, in changeform_view
>>> self.save_related(request, form, formsets, not add)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/contrib/admin/options.py", line 1015, in save_related
>>> self.save_formset(request, form, formset, change=change)
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/contrib/admin/options.py", line 1003, in save_formset
>>> formset.save()
>>>   File "/opt/virtualenv/Environments/mynetgest2/lib/python3.4/site-
>>> packages/django/forms/models.py", line 645, in save
>>> return self.save_existing_objects(commit) + self.save_new_objects(
>>> commit)
&g

Re: Crispy forms and its "coercing to unicode need string or buffer nonetype found"

2016-08-11 Thread Constantine Covtushenko
Hi Rompe,

>From you have posted I can suggest check your model.
Can you post here code of it?

Regards,

On Thu, Aug 11, 2016 at 1:11 PM, RompePC  wrote:

> I was working on an admin panel, and when I try to get to the add/update
> view of the model, it just throws this error. I've been checking Google for
> all the morning, but the solutions I've just found aren't the problem I've
> (no problem with unicode, I check if the related object is None, etc.).
>
> The exception throwed is (line 28):
>
>
> coercing to Unicode: need string or buffer, NoneType found
>
> 18
> 19 {% if field|is_checkboxselectmultiple %}
> 20 {% include 'bootstrap3/layout/checkboxselectmultiple.html' %}
> 21 {% endif %}
> 22
> 23 {% if field|is_radioselect %}
> 24 {% include 'bootstrap3/layout/radioselect.html' %}
> 25 {% endif %}
> 26
> 27 {% if not field|is_checkboxselectmultiple and not field|is_radioselect
> %}
> 28 {% if field|is_checkbox and form_show_labels %}
> 29 
> 30 {% crispy_field field %}
> 31 {{ field.label|safe }}
> 32 {% include 'bootstrap3/layout/help_text_and_errors.html' %}
> 33 
> 34 {% else %}
> 35 
> 36 {% crispy_field field %}
> 37 {% include 'bootstrap3/layout/help_text_and_errors.html' %}
> 38 
>
>
> --
> 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/65bdca52-beba-4e02-a39a-5694ccbfbd66%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boVK5TA1z6g0L68KFwzNtw8nTtXf6%3DQ49YSzgrW_wy-Dsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Parent initialization don't working

2016-08-11 Thread Constantine Covtushenko
Hi Rompe,

As for your admin models it seems like they should extend:
`admin.ModelAdmin`, see django documentation


I am not sure that this is a problem you have encountered.
But to move further please do like said in the documentation firstly.

Regards,


On Thu, Aug 11, 2016 at 1:06 PM, RompePC  wrote:

> I'll say first that I'm using *xadmin*, although it doesn't matter for
> this problem.
> Python 2.7.3 with Django 1.9.5
>
> The problem is in this piece of code (take it as an example):
>
> class ParentAdmin(object):
>def __init__(self):
>  # Boring stuff
>  self.list_filter = ["name"]
>  # Calling super()
>
> class SonAdmin(ParentAdmin):
> # Boring stuff
>
> If I set up *list_filter* in *SonAdmin*, it shows the filter and all goes
> well. But, if I set up it instead in *ParentAdmin*, it just doesn't show.
> And its weird because it works when setting list_display the same way. No
> errors throwed, and no other part of the code is the problem. I think that
> Django overrides it in some moment, but that wouldn't make sense. 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/e74c0eca-d417-4914-ab4c-df5b67bae618%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boVa%2Byekd2U5sEHtnQj_Sdmyv%2B-qC6GRdT4RwByUpxx%2BWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to use Django 1.9.5, django_pyodbc, MS SQL Server 2012 on 64bit Windows 7

2016-08-11 Thread Constantine Covtushenko
Great job done.

You welcome!

Regards,

On Thu, Aug 11, 2016 at 8:46 PM, Evan Roberts 
wrote:

>
> Thanks for the help and guidance.  I found a solution. I installed these
> libs and was able to connect:
> Django (1.9.9)
> django-pyodbc-azure (1.9.9.0)
> pip (8.1.2)
> pyodbc (3.0.10)
>
> I connected using these settings:
> DATABASES = {
> 'default': {
> 'ENGINE': 'sql_server.pyodbc',
> 'HOST': '192.168.**.**',
> 'PORT': '1433',
> 'USER': '***',
> 'PASSWORD': '**',
> 'NAME': 'mydb',
> }
> }
>
> --
> 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/d138baf7-f035-4b28-b6ab-0c279dbf5c0a%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boX07%2BBV9wndgRzK49V%3DnuBvXePri3FBUZhsq42znErpMQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Crispy forms and its "coercing to unicode need string or buffer nonetype found"

2016-08-12 Thread Constantine Covtushenko
Hi,

Sounds great.

On Fri, Aug 12, 2016 at 11:12 AM, RompePC  wrote:

> Ok, I just did again a *unicode(..)* call to a method that before worked
> without it. Sincerely, I just have no idea why now I need to do it.
>
> Solved.
>
>
> El jueves, 11 de agosto de 2016, 12:58:20 (UTC+2), RompePC escribió:
>>
>> I was working on an admin panel, and when I try to get to the add/update
>> view of the model, it just throws this error. I've been checking Google for
>> all the morning, but the solutions I've just found aren't the problem I've
>> (no problem with unicode, I check if the related object is None, etc.).
>>
>> The exception throwed is (line 28):
>>
>>
>> coercing to Unicode: need string or buffer, NoneType found
>>
>> 18
>> 19 {% if field|is_checkboxselectmultiple %}
>> 20 {% include 'bootstrap3/layout/checkboxselectmultiple.html' %}
>> 21 {% endif %}
>> 22
>> 23 {% if field|is_radioselect %}
>> 24 {% include 'bootstrap3/layout/radioselect.html' %}
>> 25 {% endif %}
>> 26
>> 27 {% if not field|is_checkboxselectmultiple and not field|is_radioselect
>> %}
>> 28 {% if field|is_checkbox and form_show_labels %}
>> 29 
>> 30 {% crispy_field field %}
>> 31 {{ field.label|safe }}
>> 32 {% include 'bootstrap3/layout/help_text_and_errors.html' %}
>> 33 
>> 34 {% else %}
>> 35 
>> 36 {% crispy_field field %}
>> 37 {% include 'bootstrap3/layout/help_text_and_errors.html' %}
>> 38 
>>
>>
>> --
> 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/8d1df6a3-f941-4df3-a31b-265872ccdd17%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXsTZk%2BQoO9h5XEGiyW%2Bvso%3D9jNtyW2%2BMkZv1s2CSRBsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ProgrammingError: (2014, "Commands out of sync; you can't run this command now")

2016-08-12 Thread Constantine Covtushenko
Hi Anoop,

I've checked that such kind of errors comes from MySQL server. You can
check detailed explanation here
.
Do you have any procedure run on your server?

On Fri, Aug 12, 2016 at 11:37 AM, ANOOP M.S  wrote:

> any idea why this happens?
>
> On Tuesday, July 8, 2008 at 11:05:27 PM UTC+5:30, Rodrigo Culagovski wrote:
>>
>> In a production site, all of a sudden while trying to edit the site
>> via the admin interface I get:
>>
>> ProgrammingError: (2014, "Commands out of sync; you can't run this
>> command now")
>>
>> This is when trying to access the record list: "/admin/core/pagina/"
>> This is only while trying to edit this one specific model ('pagina'),
>> I can edit the others without errors.
>> I dumped the database to my development server, and I get the same
>> error. It was working fine right before importing the DB from the
>> production server, so I'm thinking there's a problem in the actual DB.
>> I ran Optimize, Check and Repair on the DB in MySQL Administrator. No
>> dice.
>> I haven't updated or changed anything on either server. Development's
>> running XP, production Linux.
>>
>> Full traceback:
>>
>> Traceback (most recent call last):
>>
>>   File "C:\django\djtrunk\django\core\servers\basehttp.py", line 277,
>> in run
>> self.result = application(self.environ, self.start_response)
>>
>>   File "C:\django\djtrunk\django\core\servers\basehttp.py", line 631,
>> in __call__
>> return self.application(environ, start_response)
>>
>>   File "C:\django\djtrunk\django\core\handlers\wsgi.py", line 205, in
>> __call__
>> response = self.get_response(request)
>>
>>   File "C:\django\djtrunk\django\core\handlers\base.py", line 117, in
>> get_response
>> receivers = dispatcher.send(signal=signals.got_request_exception,
>> request=request)
>>
>>   File "C:\django\djtrunk\django\dispatch\dispatcher.py", line 360, in
>> send
>> **named
>>
>>   File "C:\django\djtrunk\django\dispatch\robustapply.py", line 47, in
>> robustApply
>> return receiver(*arguments, **named)
>>
>>   File "C:\django\djtrunk\django\db\__init__.py", line 73, in
>> _rollback_on_exception
>> transaction.rollback_unless_managed()
>>
>>   File "C:\django\djtrunk\django\db\transaction.py", line 149, in
>> rollback_unless_managed
>> connection._rollback()
>>
>>   File "C:\django\djtrunk\django\db\backends\mysql\base.py", line 195,
>> in _rollback
>> BaseDatabaseWrapper._rollback(self)
>>
>>   File "C:\django\djtrunk\django\db\backends\__init__.py", line 24, in
>> _rollback
>> return self.connection.rollback()
>>
>> ProgrammingError: (2014, "Commands out of sync; you can't run this
>> command now")
>>
> --
> 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/6894ba6a-193e-4d29-81db-0cca6f1a9a23%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boWuHCVRMvCQH6h-Ogv-UUbWFWbYBBhETYPTVQiGGYV7HQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Parent initialization don't working

2016-08-12 Thread Constantine Covtushenko
Sorry, I did not mention your point about xadmin.
Sorry again.

I've checked its github page. It seems like they do not have documentation
in English.

So may be your problem should be addressed to them?
Did you try that?

Else as for me we should go to xadmin code and check there.

On Fri, Aug 12, 2016 at 2:45 PM, RompePC  wrote:

> An intereseting point is that, even after the *super*, *list_filter* remains
> still setted (which is what I want), but then in the web page it doesn't
> show anywhere (as if you just didn't setted it). Maybe there's some hidden
> *__init__* upside model admin that do some clean?
>
> El jueves, 11 de agosto de 2016, 12:58:20 (UTC+2), RompePC escribió:
>>
>> I'll say first that I'm using *xadmin*, although it doesn't matter for
>> this problem.
>> Python 2.7.3 with Django 1.9.5
>>
>> The problem is in this piece of code (take it as an example):
>>
>> class ParentAdmin(object):
>>def __init__(self):
>>  # Boring stuff
>>  self.list_filter = ["name"]
>>  # Calling super()
>>
>> class SonAdmin(ParentAdmin):
>> # Boring stuff
>>
>> If I set up *list_filter* in *SonAdmin*, it shows the filter and all
>> goes well. But, if I set up it instead in *ParentAdmin*, it just doesn't
>> show. And its weird because it works when setting list_display the same
>> way. No errors throwed, and no other part of the code is the problem. I
>> think that Django overrides it in some moment, but that wouldn't make
>> sense. 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/631ba41c-2b1c-4876-8978-5345f0e76875%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boWhBmDTa1A%2Bxf_%2B9D%3D4w%2B97dzUYGGSFfvgr3QCaKW3sWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: DoesNotExist on ForeignKey Access

2016-08-12 Thread Constantine Covtushenko
HI guis,

I need to mention one point that works well for me.
If you check blob existence with:
  hasattr(widget, 'blob')
then django responds False in the case Blob Does Not exist an True
otherwise.

At the same time DB request is performed but DoesNotExist exception is not
raised.

On Fri, Aug 12, 2016 at 11:10 PM, TheBeardedTemplar <
thebeardedtemp...@gmail.com> wrote:

>
>
> On Friday, August 12, 2016 at 1:19:17 PM UTC-6, Todor Velichkov wrote:
>>
>> Some more code will be helpful, for example the model structure, how do
>> you define the the `ForeignKey`? How do you subscribe for the signal?
>> You are saying that with sleep(1) the code works fine, is this mean that
>> you can reproduce the problem at any time?
>> However test it without fetching the blob object, this would probably fix
>> the problem:
>>
>> if widget.blob_id is not None and Widget.objects.filter(blob_id=widget.
>> blob_id).count() == 0:
>> Blob.objects.filter(id=widget.blob_id).delete()
>>
>>
> Hello Todor,
>
> Your solution worked like a charm. It was fetching the blob object causing
> the failure, thank you very much! For the sake of completion, here is the
> code you asked for:
>
> class Widget(models.Model):
> client = models.ForeignKey(Client, related_name="layers")
> label = models.TextField()
> blob = models.ForeignKey(Blob, blank=True, null=True)
> date_created = models.DateTimeField(auto_now_add=True, blank=True,
> null=True)
>
> And the connection is made using signals.post_delete.connect(postDeleteWidget,
> sender=Widget).
>
>
> --
> 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/ea379e82-a7e5-455e-9018-007af3c7c435%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boViBOVKOERr0i_pOyOQix9KAJ%3DmtvowRQRr8ci_-aPZNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: TemplateSyntaxError when using inbuilt views

2016-08-13 Thread Constantine Covtushenko
Hi Piyush,

Welcome to community!

Can you please give us your template snipped?

Regards,


On Sat, Aug 13, 2016 at 6:48 AM, Piyush Rungta 
wrote:

> Hello this is my first time here.
> So I am trying to create directory index to serve static files uploaded by
> users by using inbuilt view by adding this to my urlpatterns -
>
>
> from django.views.static import serve
>
> url(r'^uploads/(?P.*)', serve, {
> 'document_root': settings.UPLOAD_DIR,
> 'show_indexes': True,
> },name="index_home"),
> ]
>
>
> this gave me
>
>
> TemplateSyntaxError at /uploads/
> 'i18n' is not a registered tag library. Must be one of:
>
> when trying to access the url with debug=True.
>
> I tried to register the tag library by adding this to my settings.py in in 
> TEMPLATES OPTIONS as described here 
>  and here 
> .
>
> 'libraries': {
>  'staticfiles' : 'django.templatetags.static',
>  'i18n' : 'django.templatetags.i18n',
>  },
>
>
> but still no luck. Can anyone help me with what is going wrong?
>
> Thanks
>
>
>
>
> --
> 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/f33e8cd8-e59e-42f7-849d-8962e31c66ee%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXfLQ_R1ay-drut0Us1dC%3DXTzrSEqoZaHQ0yGf66QmdBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with django form an ajax, error 500

2016-08-17 Thread Constantine Covtushenko
Hi Andrew,

To have a proper `to_python` transformation from `POST` strings please use 
forms.
They do that perfectly and also they can handle any king of user input 
validations.


form = SomeCustomForm(request.POST)
form.is_valid():
parsed_dictionary = form.cleaned_data()


As for 'Ajax'. It seems like you should manually parse body before any 
further processing. Request instance has `is_ajax 
`
 
method to detect such requests.

That can be done
import json
if request.is_ajax():
json_dict =  

On Thursday, August 18, 2016 at 4:34:33 AM UTC+3, agapito treviño wrote:
>
> Elros Romeo
>
> as defined by the form.as_p.?
> I want to implement this
>
>
>
> El viernes, 15 de julio de 2016, 18:49:00 (UTC-5), Elros Romeo escribió:
>>
>> Hi, i hope you can help me, im trying to make a django post form without 
>> reloading the page using ajax, but im getting error 500 when submit, can 
>> you help me to fix this, this is my code:
>>
>> *models.py*
>>
>> class ProductoConcepto(models.Model):
>> producto = models.ForeignKey(Producto)
>> orden = models.ForeignKey(Cobro)
>> cantidad = models.FloatField()
>>
>>
>> *urls.py*
>>
>> from django.conf.urls import patterns, include, url
>> from django.contrib import admin
>> from cobro import views
>>
>> urlpatterns = [
>> url(r'^cobro/agregar_concepto/$', views.addconcept_product, 
>> name='add_concepto'),
>> ]
>>
>> *views.py*
>>
>>
>> def addconcept_product(request):
>>
>> if request.method == 'POST':
>>
>> if form.is_valid():
>> producto = request.POST['producto']
>> orden = request.POST['orden']
>> cantidad = request.POST['cantidad']
>>
>> ProductoConcepto.objects.create(producto=producto, 
>> orden=orden, cantidad=cantidad)
>>
>> return HttpResponse('')
>>
>> *template*
>>
>> > role="dialog"  aria-hidden="true">
>> 
>> 
>> 
>> > data-dismiss="modal">
>> ×
>> Cerrar
>> 
>> Agregar nuevo 
>> concepto
>> 
>> 
>> Datos de concepto a agregar:
>> 
>> > enctype='multipart/form-data'>
>> {% csrf_token %}
>> {{form2.as_p}}
>>
>> 
>> 
>> 
>>
>> 
>> > value='Guardar' class="btn btn-w-m btn-primary"/>
>> 
>>
>> 
>> 
>> 
>> 
>> 
>> 
>>
>> 
>> $(document).on('submit', '#formulario-modal', function(e){
>> e.preventDefault();
>> $.ajax ({
>> type: 'POST',
>> url: '{% url 'add_concepto' %}',
>> data: {
>> producto: $('#id_producto').val(),
>> orden: $('#id_orden').val(),
>> cantidad: $('#id_cantidad').val(),
>> csrfmiddlewaretoken: '{{ csrf_token }}',
>> },
>> sucess:function(){
>> alert("OK");
>> }
>> })
>> });
>>
>> 
>>
>> this is the error:  POST http://127.0.0.1:8000/cobro/agregar_concepto/ 
>> 500 (Internal Server Error)
>>
>

-- 
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/238ddd6d-a084-422a-b40c-0cbc06ff9002%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with django form an ajax, error 500

2016-08-17 Thread Constantine Covtushenko
Sorry guys, please skip my previous post. It appeared unfinished.
My correct one below.

Hi Andrew,

To have a proper `to_python` transformation from `POST` strings please use 
forms.
They do that perfectly and also they can handle any king of user input 
validations.

form = SomeCustomForm(request.POST)
if form.is_valid():

parsed_dictionary = form.cleaned_data()

//some other required stuff 



As for 'Ajax'. It seems like you should manually parse body before any 
further processing. Request instance has `is_ajax 
<https://docs.djangoproject.com/en/1.10/_modules/django/http/request/#HttpRequest.is_ajax>`
 
method to detect such requests.

That can be done
import json
if request.is_ajax():

query_dict =  json.loads(request.body)


I hope it helps.

Regards,
Constantine C.

On Thursday, August 18, 2016 at 4:34:33 AM UTC+3, agapito treviño wrote:
>
> Elros Romeo
>
> as defined by the form.as_p.?
> I want to implement this
>
>
>
> El viernes, 15 de julio de 2016, 18:49:00 (UTC-5), Elros Romeo escribió:
>>
>> Hi, i hope you can help me, im trying to make a django post form without 
>> reloading the page using ajax, but im getting error 500 when submit, can 
>> you help me to fix this, this is my code:
>>
>> *models.py*
>>
>> class ProductoConcepto(models.Model):
>> producto = models.ForeignKey(Producto)
>> orden = models.ForeignKey(Cobro)
>> cantidad = models.FloatField()
>>
>>
>> *urls.py*
>>
>> from django.conf.urls import patterns, include, url
>> from django.contrib import admin
>> from cobro import views
>>
>> urlpatterns = [
>> url(r'^cobro/agregar_concepto/$', views.addconcept_product, 
>> name='add_concepto'),
>> ]
>>
>> *views.py*
>>
>>
>> def addconcept_product(request):
>>
>> if request.method == 'POST':
>>
>> if form.is_valid():
>> producto = request.POST['producto']
>> orden = request.POST['orden']
>> cantidad = request.POST['cantidad']
>>
>> ProductoConcepto.objects.create(producto=producto, 
>> orden=orden, cantidad=cantidad)
>>
>> return HttpResponse('')
>>
>> *template*
>>
>> > role="dialog"  aria-hidden="true">
>> 
>> 
>> 
>> > data-dismiss="modal">
>> ×
>> Cerrar
>> 
>> Agregar nuevo 
>> concepto
>> 
>> 
>> Datos de concepto a agregar:
>> 
>> > enctype='multipart/form-data'>
>> {% csrf_token %}
>> {{form2.as_p}}
>>
>> 
>> 
>> 
>>
>> 
>> > value='Guardar' class="btn btn-w-m btn-primary"/>
>> 
>>
>> 
>> 
>> 
>> 
>> 
>> 
>>
>> 
>> $(document).on('submit', '#formulario-modal', function(e){
>> e.preventDefault();
>> $.ajax ({
>> type: 'POST',
>> url: '{% url 'add_concepto' %}',
>> data: {
>> producto: $('#id_producto').val(),
>> orden: $('#id_orden').val(),
>> cantidad: $('#id_cantidad').val(),
>> csrfmiddlewaretoken: '{{ csrf_token }}',
>> },
>> sucess:function(){
>> alert("OK");
>> }
>> })
>> });
>>
>> 
>>
>> this is the error:  POST http://127.0.0.1:8000/cobro/agregar_concepto/ 
>> 500 (Internal Server Error)
>>
>

-- 
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/743add14-54a3-427f-9b2c-5b1b38cd676a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django query not returning all objects

2016-08-17 Thread Constantine Covtushenko
Hi Koonal,

As said in django doc
 you
can use `distinct()` to remove duplicated rows from first query.

I believe with this your pagination should works as expected.

Regards,


On Thu, Aug 18, 2016 at 2:58 AM, Koonal Bharadwaj 
wrote:

> Hello,
>
> The issue:
>
> When trying to order_by on a related model duplicate entries are created.
> I solved this with an OrderedSet that is applied after paginating (
> http://code.activestate.com/recipes/576694/). However, when I try to
> paginate the queryset, all the results are not returned. It's missing a few
> table rows.
>
> Models:
>
> class HeartFlowCase(models.Model):
> """
>
> A Hearflow Case.
>
> This serves at the true state of a case as it is processed through the 
> system.
> It also holds the results of each step of the processing.
>
> """
>
> # Primary
> hf_id = models.CharField('HeartFlow ID', max_length=200, blank=True, 
> unique=True)
> canonical_data = models.ForeignKey('cases.CaseData', to_field='uuid', 
> related_name="canonical_data")
>
>
> class CaseData(models.Model):
> """
> Extracted and computed values related to a single processing run of a 
> case.
>
> A HeartFlowCase can have multiple runs associated with it.
> The one which is accepted to be the "clinically accurate" one is the one 
> referred to as 'canonical_data' by
> the HeartFlowCase itself.
>
> """
>
> # Primary
> heartflowcase = models.ForeignKey(HeartFlowCase, related_name='data', 
> blank=True, null=True)
> uuid = models.CharField('Case Data UUID', max_length=200, blank=False, 
> null=False, unique=True)
> deadline = models.DateTimeField('Deadline', blank=True, 
> default=get_default_deadline)
>
>
> As you can see, there is a ForeignKey to canonical CaseData from
> HeartFlowCase and a ForeignKey to HeartFlowCase from CaseData. So you can
> have multiple CaseDatas per HeartFlowCase.
>
> Structure:
>
> HeartFlowCase
> |
> data - CaseData1
> \
>  \ CaseData2
>
>
> For example:
>
> Total number of HeartFlow objects are 5 with 2 CaseDatas each. If I
> order_by deadline on CaseData as:
> cases = HeartFlowCase.objects.all().order_by(data__deadline)
> this returns duplicates since there are multiple CaseDatas, which is fine.
> Now I try and paginate it by applying:
>
> paginator = Paginator(cases, 2)
> cases = paginator.page(1)
>
> Now the SQL query has a LIMIT and OFFSET given. If the order_by gives 
> duplicate HeartFlowCase objects this hits the LIMIT number and the results 
> that are returned are missing a HeartFlowCase object. So if 2 duplicates are 
> returned per case after applying the OrderedSet I get only one case back and 
> missing one case since it was never returned from the database. As I goto the 
> next page:
>
> cases = paginator.page(2)
>
> that missingHeartFlowCase object that was not returned from the first page 
> queryset is lost forever and is never displayed.
>
>
> I hope this is clear. Please let me know if I can clarify further. Any help 
> would greatly be appreciated. Thanks.
>
> --
> 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/61ec03f6-3325-49fe-bcdc-a7ca50784dc0%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boUF2mNVaU-06TWebfH5JonHvFmdqW103Q_CF1WmWShjJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django query not returning all objects

2016-08-19 Thread Constantine Covtushenko
Hi Koonal,

Sorry for not exact suggestion.

I hope that combination of  `annotate` and `values` will be helpful, see
this link for more detailed explanation
<https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#values>.

Pleas try something like following:

cases = HeartFlowCase.objects.values(‘all fields required in your view’).
annotate(min_deadline=Min('data__deadline')).order_by('min_deadline')

It is the Todor's suggestion extended with value method run.

I believe that you need `GROUP BY` in your SQL query and it generated by
`values` as said in Django documentation.

On Fri, Aug 19, 2016 at 7:10 PM, Simon Charette 
wrote:

> For reference there's a Django ticket to suggest using this technique.
>
> Cheers,
> Simon
>
> [1] https://code.djangoproject.com/ticket/19842
>
>
> Le jeudi 18 août 2016 02:20:34 UTC-4, Todor Velichkov a écrit :
>>
>> Another solution would be to annotate min/max deadline date and order by
>> the annotation. Something like:
>>
>> cases = HeartFlowCase.objects.all().annotate(min_deadline=Min('data_
>> _deadline')).order_by('min_deadline')
>>
>>
>> On Thursday, August 18, 2016 at 7:59:19 AM UTC+3, Constantine Covtushenko
>> wrote:
>>>
>>> Hi Koonal,
>>>
>>> As said in django doc
>>> <https://docs.djangoproject.com/en/1.10/ref/models/querysets/#order-by> you
>>> can use `distinct()` to remove duplicated rows from first query.
>>>
>>> I believe with this your pagination should works as expected.
>>>
>>> Regards,
>>>
>>>
>>> On Thu, Aug 18, 2016 at 2:58 AM, Koonal Bharadwaj <
>>> kbhar...@heartflow.com> wrote:
>>>
>>>> Hello,
>>>>
>>>> The issue:
>>>>
>>>> When trying to order_by on a related model duplicate entries are
>>>> created. I solved this with an OrderedSet that is applied after paginating 
>>>> (
>>>> http://code.activestate.com/recipes/576694/). However, when I try to
>>>> paginate the queryset, all the results are not returned. It's missing a few
>>>> table rows.
>>>>
>>>> Models:
>>>>
>>>> class HeartFlowCase(models.Model):
>>>> """
>>>>
>>>> A Hearflow Case.
>>>>
>>>> This serves at the true state of a case as it is processed through the 
>>>> system.
>>>> It also holds the results of each step of the processing.
>>>>
>>>> """
>>>>
>>>> # Primary
>>>> hf_id = models.CharField('HeartFlow ID', max_length=200, blank=True, 
>>>> unique=True)
>>>> canonical_data = models.ForeignKey('cases.CaseData', to_field='uuid', 
>>>> related_name="canonical_data")
>>>>
>>>>
>>>> class CaseData(models.Model):
>>>> """
>>>> Extracted and computed values related to a single processing run of a 
>>>> case.
>>>>
>>>> A HeartFlowCase can have multiple runs associated with it.
>>>> The one which is accepted to be the "clinically accurate" one is the 
>>>> one referred to as 'canonical_data' by
>>>> the HeartFlowCase itself.
>>>>
>>>> """
>>>>
>>>> # Primary
>>>> heartflowcase = models.ForeignKey(HeartFlowCase, related_name='data', 
>>>> blank=True, null=True)
>>>> uuid = models.CharField('Case Data UUID', max_length=200, blank=False, 
>>>> null=False, unique=True)
>>>> deadline = models.DateTimeField('Deadline', blank=True, 
>>>> default=get_default_deadline)
>>>>
>>>>
>>>> As you can see, there is a ForeignKey to canonical CaseData from
>>>> HeartFlowCase and a ForeignKey to HeartFlowCase from CaseData. So you
>>>> can have multiple CaseDatas per HeartFlowCase.
>>>>
>>>> Structure:
>>>>
>>>> HeartFlowCase
>>>> |
>>>> data - CaseData1
>>>> \
>>>>  \ CaseData2
>>>>
>>>>
>>>> For example:
>>>>
>>>> Total number of HeartFlow objects are 5 with 2 CaseDatas each. If I
>>>> order_by deadline on CaseData as:
>>>> cases 

Re: Custom Template Tag

2016-09-01 Thread Constantine Covtushenko
Hi All,
There is no valuable reason to do it in the template. And no matter how to
ate using it, cause template should only present view model(s).

But if you tell us your intention may be we can suggest a better place for
such request?

Regards,

On Sep 2, 2016 6:03 AM, "Al Johri"  wrote:

> Ludovic,
>
> I'm using the templates for a different purpose, not in a web framework or
> view.
>
> Thanks,
>
> Al
>
> On Thursday, September 1, 2016 at 8:09:29 AM UTC-4, ludovic coues wrote:
>>
>> I wouldn't do it this way.
>> Personally, I would make the POST request in the view function, put
>> the return value in the context. The template isn't a good place to
>> have logic. It should only take data and format them.
>>
>> 2016-09-01 5:33 GMT+02:00 Al Johri :
>> > Hi Django Users,
>> >
>> > I want to make a custom template tag where the tag's renderer needs to
>> make
>> > a POST request.
>> >
>> > https://docs.djangoproject.com/en/1.10/howto/custom-template
>> -tags/#writing-the-renderer
>> > https://docs.djangoproject.com/en/1.10/howto/custom-template
>> -tags/#thread-safety-considerations
>> >
>> > Is it possible to render the nodes of a template in multiple threads? I
>> > would ideally like those POST requests to happen at the same time.
>> >
>> > Does anyone know of some similar project?
>> >
>> > Thanks,
>> >
>> > Al
>> >
>> > --
>> > 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...@googlegroups.com.
>> > To post to this group, send email to django...@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/84ccc6dc-ae1d
>> -404c-9a05-1b72fc36a778%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
> --
> 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/7eaa219b-ddee-4fa2-8ffb-37d04f168965%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXxVGX4JT9o2%3DKrtBsFDVr%2BrY9ZVpfLruWED3NUcW58cw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Abridged summary of django-users@googlegroups.com - 35 updates in 12 topics

2016-09-14 Thread Constantine Covtushenko
Hi Juliana,

Did check this django doc
 page?
It describes basics of how to work with files. The same stands for images.

Also you can check one of the available extensions.
I was using django-filer.  It has a
great integration options for the admin site. And it allows to organise
your photos to folders/subfolders structure.

I hope that helps.


On Tue, Sep 13, 2016 at 6:13 PM, juliana kofi  wrote:

> hello am trying to upload photos on my blog how do i do that using django
> and python
>
> On Tue, Sep 13, 2016 at 3:10 PM,  wrote:
>
>> django-users@googlegroups.com
>> 
>>  Google
>> Groups
>> 
>> 
>> Today's topic summary
>> View all topics
>> 
>>
>>- Creation of default site not triggering post_save signal
>><#m_3915860844311027746_m_-517278597662460273_group_thread_0> - 2
>>Updates
>>- Problem with migration to Django 1.8
>><#m_3915860844311027746_m_-517278597662460273_group_thread_1> - 1
>>Update
>>- how to display models in templates
>><#m_3915860844311027746_m_-517278597662460273_group_thread_2> - 7
>>Updates
>>- Django with digital certificates
>><#m_3915860844311027746_m_-517278597662460273_group_thread_3> - 2
>>Updates
>>- Can't create editable foreign key field in Django admin: going to
>>give up on django
>><#m_3915860844311027746_m_-517278597662460273_group_thread_4> - 6
>>Updates
>>- Unexpected poor template performance
>><#m_3915860844311027746_m_-517278597662460273_group_thread_5> - 1
>>Update
>>- Database is not reset after StaticLiveServerTestCase (Django 1.9.5)
>><#m_3915860844311027746_m_-517278597662460273_group_thread_6> - 2
>>Updates
>>- Extracting the username:password from the host
>><#m_3915860844311027746_m_-517278597662460273_group_thread_7> - 3
>>Updates
>>- Import css in Django
>><#m_3915860844311027746_m_-517278597662460273_group_thread_8> - 4
>>Updates
>>- create connection error
>><#m_3915860844311027746_m_-517278597662460273_group_thread_9> - 2
>>Updates
>>- Django Ticketing Application
>><#m_3915860844311027746_m_-517278597662460273_group_thread_10> - 3
>>Updates
>>- Regex Validators doesn't validate while working in a shell
>><#m_3915860844311027746_m_-517278597662460273_group_thread_11> - 2
>>Updates
>>
>> Creation of default site not triggering post_save signal
>> 
>> Matt Thompson : Sep 12 07:59PM -0700
>>
>> Hi Simon,
>>
>> Thank you very much for your prompt reply! I've added the following to my
>> app, which seems to work just fine:
>>
>> @receiver(models.signals.post_migrate) ...more
>> 
>> Simon Charette : Sep 13 05:58AM -0700
>>
>> Hi Matt,
>>
>> The recommended pattern is to register signal receivers in your app
>> config's
>> ready() method[1]. From the Django documentation:
>>
>> > Where should this code live?
>>
>> > Strictly speaking, ...more
>> 
>> Back to top <#m_3915860844311027746_m_-517278597662460273_digest_top>
>> Problem with migration to Django 1.8
>> 
>> alessandro.henri...@labcodes.com.br: Sep 12 09:31AM -0700
>>
>> Hello,
>>
>> I'm currently trying to migrate a project from django 1.5.1 to the newest
>> version. I got stuck in the version 1.7. The only test that is not
>> passing
>> was made to try to get the e-mail ...more
>> 
>> Back to top <#m_3915860844311027746_m_-517278597662460273_digest_top>
>> how to display models in templates
>> 
>> Timothy Steele : Sep 13 12:33AM -0700
>>
>> please i try my best but i can display my models in a templates i have
>> just
>> created.
>>
>> *Please have a look at the codes in the models.py file*
>>
>> from django.db import models
>> from ...more
>> 
>> ludovic coues : Sep 13 09:44AM +0200
>>
>> Can you try this in your template ?
>>
>> {{ bookmarks|pprint }}
>> {% for bookmark in bookmaks %}
>> {{ bookmark|pprint }}
>> {% endfor %}
>>
>

Re: download file when debug=false

2016-09-30 Thread Constantine Covtushenko
Hi Richard,

There are a lot of options of how to change/switch application behaviour.
It depends on what  you eventually need to get.

Mentioned solution: settings.DEBUG = true/false can be one of them

Hope it helps.

Regards,
Constantine C.

> On Sep 30, 2016, at 12:06, Richard Auscard  wrote:
> 
> hello,
> 
> i have developp a django application where excel file are generate after some 
> operation. when debug=true thes excel files can be download but when false it 
> is not possible.
> my question is how to solve this issus.
> 
> all think are ok when debug=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 
> <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/1075ee7d-6927-47ee-8196-243a3d5091f5%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/1075ee7d-6927-47ee-8196-243a3d5091f5%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <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/7C753B1A-8DAD-4CFD-8C4E-330AABC755AA%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: download file when debug=false

2016-10-01 Thread Constantine Covtushenko
Hi Richard,

Ah, I missed your point last time. Sorry for that.

Can you please print here code sniped with with your app returns excel file?
It helps us to suggest something valuable.

Regards,

> On Sep 30, 2016, at 12:06, Richard Auscard  wrote:
> 
> hello,
> 
> i have developp a django application where excel file are generate after some 
> operation. when debug=true thes excel files can be download but when false it 
> is not possible.
> my question is how to solve this issus.
> 
> all think are ok when debug=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/1075ee7d-6927-47ee-8196-243a3d5091f5%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7205B739-0589-40B5-8E20-8C4B32DC05D8%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django app crashes with out of memory

2016-10-10 Thread Constantine Covtushenko
Hi Dmitry,

Please check that documentation page
.
As you can see iterator() loads all in the memory and after that returns an
iterator.

Try to fetch records say by 50 - 100 items.

Hope that helps.

On Mon, Oct 10, 2016 at 2:14 PM, Горобец Дмитрий  wrote:

> Hello.
>
> Thanks for advices.
>
> Crash occures, when I run Django command through python manage.py
> my_command_name.
>
> It doesn't relate to nginx and even gunicorn, because, again, it's Django
> command, which I call from shell.
>
> I switched off redis caching (I use cacheops), but it' didn't help too.
>
> пятница, 7 октября 2016 г., 13:21:48 UTC+5 пользователь Горобец Дмитрий
> написал:
>
>> Hello.
>>
>> I have VPS with 2Gb RAM with django, gunicorn, mysql, nginx and redis.
>>
>> My app crashes with out of memory error, when I run django command on
>> model, which has approximately 7 million records. It takes each premise
>> object and updates one field by checking value with regular expression.
>> Please, help optimize that command.
>>
>> class Command(BaseCommand):
>> help = 'Updates premise.number_order'
>>
>> def handle(self, *args, **options):
>> for premise in Premise.objects.iterator():
>> premise.number_order = premise.set_number_order()
>> premise.save()
>>
>> self.stdout.write('Finished')
>>
>>
>> # Method of Premise model
>> def set_number_order(self):
>> tr = {
>> 'А': '.10',
>> 'A': '.10',
>> 'Б': '.20',
>> 'В': '.30',
>> 'Г': '.40',
>> 'Д': '.50',
>> 'Е': '.60',
>> 'Ж': '.70',
>> 'З': '.80',
>> 'И': '.90',
>> }
>>
>> only_digit = re.compile(r'^(?P[0-9]{1,9})$')
>> digit_with_separator = re.compile(r'^(?P[0-9]
>> {1,9})(?P[-|/])(?P\w+)$')
>> digit_with_letter = re.compile(r'^(?P[0-9]
>> {1,9})(?P[А-Яа-я]+)')
>> result = 0
>> title = self.title.strip().upper()
>>
>> if only_digit.match(title):
>> number = only_digit.match(title).group('number')
>> result = number + '.00'
>>
>> elif digit_with_separator.match(title):
>> number = digit_with_separator.match(title).group('number')
>> rest = digit_with_separator.match(title).group('rest')
>> if rest[0].isalpha():
>> floating = tr.get(rest[0], '.90')
>> result = number + floating
>>
>> elif rest[0].isdigit():
>> try:
>> if rest[1].isdigit():
>> result = number + '.{}'.format(rest[:2])
>> else:
>> result = number + '.0{}'.format(rest[0])
>> except IndexError:
>> result = number + '.0{}'.format(rest[0])
>>
>> elif digit_with_letter.match(title):
>> number = digit_with_letter.match(title).group('number')
>> letter = digit_with_letter.match(title).group('letter')[0]
>>
>> floating = tr.get(letter, '.90')
>> result = number + floating
>>
>> return Decimal(result)
>>
> --
> 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/2e87323c-294c-4b82-89dd-783e36e23291%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boUAy-8NfaoG8Hmvge2dNWps2baBc4tfHa0mOrV9MNEw8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch Error using Django + Haystack + Elasticsearch

2016-10-15 Thread Constantine Covtushenko
Hi Aline,

I did not use Haystack but I am using ElastickSearch.
I carefully read you post on StackOverflow and see that search form returns
author of the post without `pk` key defined.

Did you check what is returned by ElastickSearch?
May be your SearchForm returns exactly what Elastick stores in its index? I
mean that post returned by SearchForm not the same as Post model? It can be
dictionary or something?

Sorry I do not have time to build test app to check my idea.

You can easily set up a break point and check what are the posts inside
your `post_search` view function.

Regards,
Constantine C.

On Sat, Oct 15, 2016 at 12:48 AM, Aline C. R. Souza 
wrote:

> Hello everybody,
>
> I am having a issue using Django + Haystack + Elasticsearch to perform a
> website search.
>
> I made a question on StackOverflow, but I had no satisfatory answer.
>
> The problem is in this line:
>
> by {{ post.author
> }}
>
> post.author.pk works well when called by several views, but it is not
> resolved when called by the search.
>
> There is another way to get the pk of the author of the post?
>
> The link of the StackOverflow question: http:/
> /stackoverflow.com/questions/40033039/noreversematch-error-
> using-haystack-elasticsearch
>
> Can someone help me? Please explain in details, because I am new in
> Django, and in haystack, elasticsearch...
>
>
> --
> 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/fb151afb-35a8-4ac4-a9e4-69f4419568c1%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/fb151afb-35a8-4ac4-a9e4-69f4419568c1%40googlegroups.com?utm_medium=email&utm_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/CAK52boUrkqTgVTjcDqrFqoDeH0nO56HiSJ9HKvncu9bP%3DDF_Eg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic choice option for select filed in Multivaluefield

2016-10-15 Thread Constantine Covtushenko
Hi Saranya,

Please try in TestForm
> self.fields['t'].fields[1].widget.choices = ((1,1),)

Hope it helps

On Fri, Oct 14, 2016 at 9:31 AM, saranya k 
wrote:

> I want to set choices for ChoiceField in MultiValueField in form init. But 
> its not getting updated.
> class TestField(forms.MultiValueField):
>
> def __init__(self,*args, **kwargs):
>
>
>
> error_messages = {
>
> 'incomplete': 'incomplete',
>
> }
>
> a = forms.ChoiceField(choices=((1,'a'),),required=True)
>
> b =forms.ChoiceField(choices=((2,'b'),),required=True)
>
> c = forms.ChoiceField(choices=((3,'c'),),required=True )
>
> fields = (a,b,c )
>
> widget = TestWidget(mywidgets=[fields[0].widget, fields[1].widget, 
> fields[2].widget])
>
> super(TestField, self).__init__(
>
> error_messages=error_messages, fields=fields,widget=widget,
>
> require_all_fields=True, *args, **kwargs
>
> )
>
> def compress(self, data_list):
>
> if data_list:
>
> return 
> {'academic':data_list[0],'ugs':data_list[1],'stu_sec':data_list[2]}
>
>
>
> class TestWidget(widgets.MultiWidget):
>
> def __init__(self, mywidgets,attrs=None):
>
> _widgets = (
>
> widgets.Select(attrs=attrs, choices=mywidgets[0].choices),
>
> widgets.Select(attrs=attrs,choices=mywidgets[1].choices),
>
> widgets.Select(attrs=attrs,choices=mywidgets[2].choices),
>
> )
>
> super(TestWidget, self).__init__(_widgets, attrs)
>
>
>
>
>
> def decompress(self, value):
>
> if value:
>
> return [value['academic'], value['ugs'], value['stu_sec']]
>
> return [None, None, None]
>
>
>
>
>
> class TestForm(forms.Form):
>
>   t=TestField()
>
>def __init__(self, *args, **kwargs):
>
>super(TestForm, self).__init__(*args, **kwargs)
>
>self.fields['t'].fields[1].choices = ((1,1),)
>
>
>
> Help me to achieve 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/518fa1e4-e3de-47fc-8051-22cf19df3de6%40googlegroups.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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boWju5PPTBi%2Bp9GKFesESAXwSiLBywqGTFhVaEBHWQ%3DGXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: HELP - Django variable in style (width) attribute

2016-10-15 Thread Constantine Covtushenko
Hi Aline,

It is not direct answer for what you are asking,
but why do you calculate the percentage 2 times?

Why just use `with
<https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#with>` tag?

With it nor problem at all.

Hope that helps.

Regards,
Constantine C.

On Sun, Oct 16, 2016 at 5:53 AM, James Schneider 
wrote:

>
> > Why the template tag call {% get_percentage question.pk choice.pk %}
> works inside the span tag, but doesn't work in style (width) attribute?
> >
> > What is wrong?
> >
>
> No idea. You haven't provided what your template tag does, or what the
> rendered template looks like.
>
> What does the final HTML look like?
>
> -James
>
> --
> 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/CA%2Be%2BciV9%2Bp79D4Gkst8khnhmDVt3nUOrA2C6-
> uWXgmVi8p-rDw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV9%2Bp79D4Gkst8khnhmDVt3nUOrA2C6-uWXgmVi8p-rDw%40mail.gmail.com?utm_medium=email&utm_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/CAK52boXdjG1_YJuYcQj-iRNsXezKhCOSrHA6_y5AmOmwZ7Uhbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploy on Heroku Error

2016-10-21 Thread Constantine Covtushenko
Hi Aline,

I have encountered the problem described by you as well. I am using heroku
for about 5 django projects.

For some reason this problem does not exist when you run django server with
manage.py command.

Try to read that heroku
<https://devcenter.heroku.com/articles/deploying-python#build-your-app-and-run-it-locally>
article. Using `heroku local` command helps fix/run/check locally and after
all ok you safely commit and push to heroku.

Hope that helps

Regards,
Constantine C.

On Fri, Oct 21, 2016 at 8:39 AM, Antonis Christofides <
anto...@djangodeployment.com> wrote:

> Hello,
>
> Link to the repo: https://github.com/alinecrsouza/django-blog-app
>
>
> that repo only contains the blog app. Could you show us the polls app?
>
> Regards,
>
> Antonis Christofideshttp://djangodeployment.com
>
> On 2016-10-20 22:49, Aline C. R. Souza wrote:
>
> Hello everybody,
>
> I am catching an error on trying to deploy my app on heroku. This is the
> traceback:
>
>   File "/app/.heroku/python/lib/python3.5/site-packages/polls/admin.py",
> line 3, in 
> 2016-10-20T18:42:46.734824+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in
> import_module
> 2016-10-20T18:42:46.734830+00:00 app[web.1]: ImportError: No module named
> 'models'
> 2016-10-20T18:42:46.735201+00:00 app[web.1]: [2016-10-20 18:42:46 +]
> [7] [INFO] Worker exiting (pid: 7)
> 2016-10-20T18:42:46.734826+00:00 app[web.1]: from models import Poll,
> Choice, Vote
> 2016-10-20T18:42:46.736625+00:00 app[web.1]: [2016-10-20 18:42:46 +]
> [8] [ERROR] Exception in worker process
>
> The app runs normally on localhost.
>
> That is what I tried to do: I went to my virtualenv directory at
> site-packages/polls/ and changed all the imports to polls.models instead of
> .models. Then, I cleaned the cache of the polls app and the cache of the
> blog app (blog app uses polls app). Built my app again and ran it locally.
> The app looks fine. So, I tried to push to heroku and run the app, but the
> same error occurs.
>
> Any thoughts?
>
> Link to the repo: https://github.com/alinecrsouza/django-blog-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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/8704854e-48ab-460e-8ff1-cedc427cb037%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8704854e-48ab-460e-8ff1-cedc427cb037%40googlegroups.com?utm_medium=email&utm_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/cdd71b29-ab8f-3736-71b3-ded998a6b82c%
> 40djangodeployment.com
> <https://groups.google.com/d/msgid/django-users/cdd71b29-ab8f-3736-71b3-ded998a6b82c%40djangodeployment.com?utm_medium=email&utm_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/CAK52boVpRZ2o_7b9mLcsA31aMSJmRySN6%3D0FM8uDSsjd3eHw8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploy on Heroku Error

2016-10-21 Thread Constantine Covtushenko
Hi Aline,

I thought that an initial idea of running application with `heroku local`
is to check how it can run in heroku.

Why did you change the Procfile in such a way?
It supposed to use it the same as for heroku.

Can you please try with Procfile without any local specific modifications?

Regards,
Constantine C.

On Fri, Oct 21, 2016 at 1:14 PM, Aline C. R. Souza 
wrote:

> Hello, Constantine,
>
> I have already followed this article and using `heroku local` the app runs
> fine. However, some things I did different:
>
> (i) I used psycopg2==2.6.2 instead of psycopg2==2.5.3, because the 2.5.3
> version do not works with Visual Studio Community 2015.
> (ii) On my Procfile I put: 'web: python manage.py runserver 0.0.0.0:80'
> instead of 'web: python manage.py runserver 0.0.0.0:$PORT', because, for
> some reason, 0.0.0.0:$PORT catches an error of port not found, or
> something like that.
>
> I think the problem occurs only with gunicorn server.
>
> I was thinking in test the app on a linux virtual machine, using the
> gunicorn. However, I don't know how to migrate the virtual enviroment to
> the virtual machine.
>
> So, I don't know if this would be a good approach to solve the problem.
>
> Em sexta-feira, 21 de outubro de 2016 05:27:45 UTC-2, Constantine
> Covtushenko escreveu:
>>
>> Hi Aline,
>>
>> I have encountered the problem described by you as well. I am using
>> heroku for about 5 django projects.
>>
>> For some reason this problem does not exist when you run django server
>> with manage.py command.
>>
>> Try to read that heroku
>> <https://devcenter.heroku.com/articles/deploying-python#build-your-app-and-run-it-locally>
>> article. Using `heroku local` command helps fix/run/check locally and after
>> all ok you safely commit and push to heroku.
>>
>> Hope that helps
>>
>> Regards,
>> Constantine C.
>>
>> On Fri, Oct 21, 2016 at 8:39 AM, Antonis Christofides <
>> ant...@djangodeployment.com> wrote:
>>
>>> Hello,
>>>
>>> Link to the repo: https://github.com/alinecrsouza/django-blog-app
>>>
>>>
>>> that repo only contains the blog app. Could you show us the polls app?
>>>
>>> Regards,
>>>
>>> Antonis Christofideshttp://djangodeployment.com
>>>
>>> On 2016-10-20 22:49, Aline C. R. Souza wrote:
>>>
>>> Hello everybody,
>>>
>>> I am catching an error on trying to deploy my app on heroku. This is the
>>> traceback:
>>>
>>>   File "/app/.heroku/python/lib/python3.5/site-packages/polls/admin.py",
>>> line 3, in 
>>> 2016-10-20T18:42:46.734824+00:00 app[web.1]:   File
>>> "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in
>>> import_module
>>> 2016-10-20T18:42:46.734830+00:00 app[web.1]: ImportError: No module
>>> named 'models'
>>> 2016-10-20T18:42:46.735201+00:00 app[web.1]: [2016-10-20 18:42:46
>>> +] [7] [INFO] Worker exiting (pid: 7)
>>> 2016-10-20T18:42:46.734826+00:00 app[web.1]: from models import
>>> Poll, Choice, Vote
>>> 2016-10-20T18:42:46.736625+00:00 app[web.1]: [2016-10-20 18:42:46
>>> +] [8] [ERROR] Exception in worker process
>>>
>>> The app runs normally on localhost.
>>>
>>> That is what I tried to do: I went to my virtualenv directory at
>>> site-packages/polls/ and changed all the imports to polls.models instead of
>>> .models. Then, I cleaned the cache of the polls app and the cache of the
>>> blog app (blog app uses polls app). Built my app again and ran it locally.
>>> The app looks fine. So, I tried to push to heroku and run the app, but the
>>> same error occurs.
>>>
>>> Any thoughts?
>>>
>>> Link to the repo: https://github.com/alinecrsouza/django-blog-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...@googlegroups.com.
>>> To post to this group, send email to django...@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/ms
>>> gid/django-users/8704854e-48ab-460e-8ff1-cedc427cb037%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/8704854e-48ab-460e-8ff1-cedc427cb037%40googlegroups.com?utm_medium

Re: Admin Email From Address

2016-11-14 Thread Constantine Covtushenko
Hi Matthew,

There should be considered following:
1. Not always cod runs with user interaction - worker cases
2. Not always user authenticated

With such cases who the sender should be?

Regards,
Constantine C.

On Nov 15, 2016 12:43 AM, "Matthew Pava"  wrote:

I would like to be able to change the ‘from’ address of the admin error
emails in production environments to be the email address of the user that
generated the error.  It would be convenient in triaging errors rather
quickly.



I did examine the Django source code, but it doesn’t appear to be possible
without writing my own custom function.  Any ideas?



Thank you!



-- 
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/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL
<https://groups.google.com/d/msgid/django-users/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL?utm_medium=email&utm_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/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Admin Email From Address

2016-11-15 Thread Constantine Covtushenko
Sorry but I do not see any valuable reason of doing things in such way.

Email is sent from wrong sender.
And if someone decides to email back than those user would be confused.

It is better to call things by its name.

On Tue, Nov 15, 2016 at 4:05 PM, Matthew Pava  wrote:

> In such cases, we would have a fallback that is already established in the
> settings file.
>
>
>
> *From:* django-users@googlegroups.com [mailto:django-users@
> googlegroups.com] *On Behalf Of *Constantine Covtushenko
> *Sent:* Tuesday, November 15, 2016 12:46 AM
> *To:* django-users@googlegroups.com
> *Subject:* Re: Admin Email From Address
>
>
>
> Hi Matthew,
>
> There should be considered following:
> 1. Not always cod runs with user interaction - worker cases
> 2. Not always user authenticated
>
> With such cases who the sender should be?
>
> Regards,
> Constantine C.
>
>
>
> On Nov 15, 2016 12:43 AM, "Matthew Pava"  wrote:
>
> I would like to be able to change the ‘from’ address of the admin error
> emails in production environments to be the email address of the user that
> generated the error.  It would be convenient in triaging errors rather
> quickly.
>
>
>
> I did examine the Django source code, but it doesn’t appear to be possible
> without writing my own custom function.  Any ideas?
>
>
>
> Thank you!
>
>
>
> --
> 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/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL
> <https://groups.google.com/d/msgid/django-users/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL?utm_medium=email&utm_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/CAK52boX3QBmimdd3z5YSbKDOAMOeD
> rX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com?utm_medium=email&utm_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/e85597c0b8634f46ae5d1f6ede73abdd%40ISS1.ISS.LOCAL
> <https://groups.google.com/d/msgid/django-users/e85597c0b8634f46ae5d1f6ede73abdd%40ISS1.ISS.LOCAL?utm_medium=email&utm_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/CAK52boXM8Eg9aDpHOmZOqCHSne55e_DwMYWHRBF%3D086VsNDhbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Admin Email From Address

2016-11-15 Thread Constantine Covtushenko
As I know all error emails are sent within logger handler: 'mail_admins'.

I would suggest to override 'AdminEmailHandler' and 'mail_admins'.

for more information check logging documentation
<https://docs.djangoproject.com/en/1.10/topics/logging/>.

Hope that helps

On Tue, Nov 15, 2016 at 10:31 PM, Matthew Pava  wrote:

> The error emails only go to the admins: me.  I would not be confused
> because the subject line of the email indicates that it is coming from the
> Django app starting with [Django].  The value in receiving the emails with
> the user’s email address is so that if, for instance, the president of the
> company gets an error page or anyone else gets an error page, I can very
> quickly determine which error I should focus on by simply glancing on who
> the email is from.  (In this case, the president…)
>
>
>
> *From:* kostyak7...@gmail.com [mailto:kostyak7...@gmail.com] *On Behalf
> Of *Constantine Covtushenko
> *Sent:* Tuesday, November 15, 2016 2:27 PM
>
> *To:* django-users@googlegroups.com
> *Subject:* Re: Admin Email From Address
>
>
>
> Sorry but I do not see any valuable reason of doing things in such way.
>
>
>
> Email is sent from wrong sender.
>
> And if someone decides to email back than those user would be confused.
>
>
>
> It is better to call things by its name.
>
>
>
> On Tue, Nov 15, 2016 at 4:05 PM, Matthew Pava 
> wrote:
>
> In such cases, we would have a fallback that is already established in the
> settings file.
>
>
>
> *From:* django-users@googlegroups.com [mailto:django-users@
> googlegroups.com] *On Behalf Of *Constantine Covtushenko
> *Sent:* Tuesday, November 15, 2016 12:46 AM
> *To:* django-users@googlegroups.com
> *Subject:* Re: Admin Email From Address
>
>
>
> Hi Matthew,
>
> There should be considered following:
> 1. Not always cod runs with user interaction - worker cases
> 2. Not always user authenticated
>
> With such cases who the sender should be?
>
> Regards,
> Constantine C.
>
>
>
> On Nov 15, 2016 12:43 AM, "Matthew Pava"  wrote:
>
> I would like to be able to change the ‘from’ address of the admin error
> emails in production environments to be the email address of the user that
> generated the error.  It would be convenient in triaging errors rather
> quickly.
>
>
>
> I did examine the Django source code, but it doesn’t appear to be possible
> without writing my own custom function.  Any ideas?
>
>
>
> Thank you!
>
>
>
> --
> 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/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL
> <https://groups.google.com/d/msgid/django-users/29de56e899934c489630983151e28092%40ISS1.ISS.LOCAL?utm_medium=email&utm_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/CAK52boX3QBmimdd3z5YSbKDOAMOeD
> rX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK52boX3QBmimdd3z5YSbKDOAMOeDrX6iF3NzvsLs-fNx2PO1g%40mail.gmail.com?utm_medium=email&utm_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/e85597c0b8634f46ae5d1f6ede73abdd%40ISS1.ISS.LOCAL
> <https://groups.google.com/d/msgid/django-users/e85597c0b8634f46ae5d1f6ede73abdd%40ISS1.ISS.LOCAL?utm_medium=email&a

Re: Serving external files with Django

2017-01-02 Thread Constantine Covtushenko
Hi Priyesh,

You can start from managing files
 documentation of
Django.

Hope that helps

On Mon, Jan 2, 2017 at 6:16 PM, Priyesh Raj  wrote:

> Hi,
>
> I need to serve content of external files on user action (Click on URL).
> The files are PDF and are not part of media or static files.
>
> How can I serve them in Django? Is there any built in way to handle it?
>
> Thanks
>
> --
> 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/CAOMjGk-7iQmg%3DKwzUJ2vgYryb4ODFnmRfLdHJFC8w
> PKeVW0hqA%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXE-YfwJU8M-%2ByKu2zuE0hvVyWL-OBd9xAFa7KKsyVaDw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django search

2017-01-15 Thread Constantine Covtushenko
Hi Branco,

Sorry, but can you be more specific?
If you've got the result what is your concern?
Do you only need to switch into forms?

Regards,
Constantine C.

On Sun, Jan 15, 2017 at 2:41 PM, Branko Zivanovic <
international11...@gmail.com> wrote:

> How do i implement search on django website with select menu and checkbox?
> I've succeeded in adding basic text input and it works but I didn't use
> django forms. How do I add this type of search?
>
> --
> 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/078841f1-a976-4c22-bb2f-ff5069bdce1d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/078841f1-a976-4c22-bb2f-ff5069bdce1d%40googlegroups.com?utm_medium=email&utm_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/CAK52boVnKQDnXwOtKpSaU-cQGJz6E-eW9L-71C%3DAoTnr9gth2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Login form error not showing up for wrong username/password combo

2017-12-02 Thread Constantine Covtushenko
Hi Tom,

It seems like your are trying to show error that relates to form rather to
particular field.
I see '__all__' key in example from console.

And you did not create any html tag to show such errors on the page.
All I see that you printed just field specific errors.

Probably you should print at the top of your form something like this:
*{{ form.non_field_errors }}*

Regards,
Constantine C.

On Sat, Dec 2, 2017 at 12:38 AM, Tom Tanner 
wrote:

> I have this code in my login form.
>  {% for field in login_form %}
>   {{ field }}
>   {% if field.errors %}
>{{ field.errors.as_text|cut:"* "|escape }}
>   {% endif %}
>  {% endfor %}
>
> The user must enter a valid email address in the "username" field. If the
> user enters a string not formatted like an email, I'll see this error in
> the `p` tag: "Enter a valid email address."
>
> But if the user enters a bad email/password combo, nothing shows up. In my
> `views.py`, I have a section that looks something like
> if login_form.is_valid:
>   ...
> else:
>   print login_form.errors
>
> Here's what Django prints to console. "__all__ class="errorlist nonfield">Please enter a correct username and
> password. Note that both fields may be case-sensitive.
> "
>
> Why does the error print to console but not into my `p` tag?
>
> --
> 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/f4dfcfa5-c687-439e-9e3a-8cb6f0b2c826%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/f4dfcfa5-c687-439e-9e3a-8cb6f0b2c826%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: How to save foreign key along with parent object in django 1.10

2017-12-04 Thread Constantine Covtushenko
Hi,

Can you please describe why you did not want to call author.save()
explicitly?
What is wrong with this approach?

Regards,
Constantine C.

On Mon, Dec 4, 2017 at 7:36 PM, Priyanka Thakur 
wrote:

> Hi,
>
>
> I want to create a bunch of objects that are interconnected in my  model
> (eg, one Book and one Author object) and then call save() on  the Book
> object to add everything to the database. In other words, I  don't want to
> save Author object explicitly.
>
> Example:
>
> class Author(models.Model):
>   name = models.CharField(max_length=255L, blank=True)
>
>
> class Book(models.Model):
> author = models.ForeignKey(Author)
>
>
> I want to do:
>
>
> author = Author('Robert Frost')
>
> book = Book(author)
>
> book.save()
>
> Can this be done in Django 1.10 ?
>
> Regards,
> Priyanka
>
> --
> 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/db02ab72-45a3-4f5d-a256-3a32bb4a35d7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/db02ab72-45a3-4f5d-a256-3a32bb4a35d7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boXJeP-ACPxWuY804ZE%2BvXnpiwu9DgBm9eAU0Dng%2BkPhfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need Help with Many to Many Fields

2017-12-08 Thread Constantine Covtushenko
Hi Mark,

Answering on your question I would do in your `get_documents` method:

return obj.document.all().values_list('title', flat=True)

this will get list of all document titles.

But at the same time why do you need get_documents method? How do you use
it?
May be it is better to optimize `get_queryset` of CollecionAdmin instead?

Regards,
Constantine C.

On Fri, Dec 8, 2017 at 8:07 PM, Mark Phillips 
wrote:

> I have two models -
>
> class Document(models.Model):
> document_id = models.AutoField(primary_key=True)
> title = models.CharField('title', max_length=200)
>
> class Meta:
> ordering = ['title']
>
> def __str__(self):
> return "%s" % (self.title)
>
> class Collection(models.Model):
> collection_id = models.AutoField(primary_key=True)
> name = models.CharField('title', max_length=200)
> description = models.TextField('description')
> document = models.ManyToManyField(Document,)
>
> In admin.py, I am trying to show the documents that are in a collection. I
> have this:
>
> class CollectionAdmin(admin.ModelAdmin):
> filter_horizontal = ('document',)
> list_display = ('name', 'description', 'get_documents')
>
> def get_documents(self, obj):
> documents = Collection.objects.filter(
> collection_id=obj.collection_id).values('document')
> templist = []
> for doc in documents:
> d = Document.objects.get(document_id=doc['document']).title
> templist.append(d)
> return templist
>
> My question is, I getting the titles of the documents in the collection
> correctly? Is there some way to get a queryset to look up the Document
> fields directly, or do I have to make two queries as I am doing?
>
> Thanks!
>
> Mark
>
>
> --
> 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/CAEqej2NmUSH-W2_Fd9WkmPjZzj5krk2Qmw4DyaWBkj5_
> mj46Kw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAEqej2NmUSH-W2_Fd9WkmPjZzj5krk2Qmw4DyaWBkj5_mj46Kw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Need Help with Many to Many Fields

2017-12-09 Thread Constantine Covtushenko
Hi Mark,

You should not create 2 methods.
Just change that first to be like:

return obj.document.all().values_list('field_1', 'field_2')

With this you will get QuerySet of tuples, like


I believe it should solve your problem.

Also for more references about values_list, check following documentation
page:
https://docs.djangoproject.com/en/2.0/ref/models/querysets/#values-list

Regards,
Constantine C.

On Sat, Dec 9, 2017 at 12:41 AM, Mark Phillips 
wrote:

> The point of the queries is to get information about the underlying
> Documents in each Collection, and display it in the admin page. For
> example, title is one attribute, but there are also other that I want to
> display.
>
> Your idea obj.document.all().values_list('title', flat=True) makes a lot
> of sense - Thanks!
>
> Now, a bigger question. Say I have two fields in Documents that I want to
> display side by side in a table in the Collection admin page. I would have
> two entries in the list_display:
>
> list_display = ('get_field_1', 'get_field_2', )
>
> and two functions, and each one calls obj.document.all(), which returns a
> query set of Documents in this particular Collection.
>
> def get_field_1(self, obj):
> tempstr = ""
> documents = obj.document.all()
> for d in documents:
> tempstr = tempstr + d.field_1
> return tempstr
>
> def get_field_2(self, obj):
> tempstr = ""
> documents = obj.document.all()
> for d in documents:
> tempstr = tempstr + d.field_2
> return tempstr
>
> These two "list of fields" from the Documents are displayed side by side.
> Will the first entry in the field_1 list always correspond to the first
> entry in the field_2 list? In other words, I am concerned about the order
> of the documents returned in the query set obj.document.all(). Will it
> always be the same?
>
> Perhaps a picture will help (I hope it comes through). Note the ordered
> lists of file names and thumbnails. I used the code above (with a few
> modifications) to generate the table. My concern is if the file name in the
> first list (a field in the Document model) will always correspond to the
> thumbnail in the second column (another field in the Document model).
>
> Thanks!
>
> On Fri, Dec 8, 2017 at 7:56 PM, Constantine Covtushenko <
> constantine@gmail.com> wrote:
>
>> Hi Mark,
>>
>> Answering on your question I would do in your `get_documents` method:
>>
>> return obj.document.all().values_list('title', flat=True)
>>
>> this will get list of all document titles.
>>
>> But at the same time why do you need get_documents method? How do you use
>> it?
>> May be it is better to optimize `get_queryset` of CollecionAdmin instead?
>>
>> Regards,
>> Constantine C.
>>
>> On Fri, Dec 8, 2017 at 8:07 PM, Mark Phillips > > wrote:
>>
>>> I have two models -
>>>
>>> class Document(models.Model):
>>> document_id = models.AutoField(primary_key=True)
>>> title = models.CharField('title', max_length=200)
>>>
>>> class Meta:
>>> ordering = ['title']
>>>
>>> def __str__(self):
>>> return "%s" % (self.title)
>>>
>>> class Collection(models.Model):
>>> collection_id = models.AutoField(primary_key=True)
>>> name = models.CharField('title', max_length=200)
>>> description = models.TextField('description')
>>> document = models.ManyToManyField(Document,)
>>>
>>> In admin.py, I am trying to show the documents that are in a collection.
>>> I have this:
>>>
>>> class CollectionAdmin(admin.ModelAdmin):
>>> filter_horizontal = ('document',)
>>> list_display = ('name', 'description', 'get_documents')
>>>
>>> def get_documents(self, obj):
>>> documents = Collection.objects.filter(coll
>>> ection_id=obj.collection_id).values('document')
>>> templist = []
>>> for doc in documents:
>>> d = Document.objects.get(document_id=doc['document']).title
>>> templist.append(d)
>>> return templist
>>>
>>> My question is, I getting the titles of the documents in the collection
>>> correctly? Is there some way to get a queryset to look up the Document
>>> fields directly, or do I have to make two queries as I am doing?
>>>
>>&

Re: Need Help with Many to Many Fields

2017-12-09 Thread Constantine Covtushenko
Hi Marks,

Ok, I would use `prefetch_related` method then.
https://docs.djangoproject.com/en/2.0/ref/models/querysets/#prefetch-related

you should override `get_queryset` with something like that:

def get_queryset(self, request):
return super().get_queryset(request).prefetch_related('document')

> In your model you specified `document` not `documents` that is why I used
`document`

With this all related document would be already in memory.
In your methods you can do something like this:

def get_field_1(self, obj):
return ''.join([q.field_1 for q in obj.document.all()])

And use the same approach for second method

Does it make any sense?

Regards,
Constantine C.

On Sat, Dec 9, 2017 at 11:32 AM, Mark Phillips 
wrote:

> should have been
>
> class CollectionAdmin(admin.ModelAdmin)
> in the above post.
>
> Mark
>
> On Sat, Dec 9, 2017 at 9:16 AM, Mark Phillips 
> wrote:
>
>> Hit send by accident...
>>
>> Constantine,
>>
>> Thanks for the link and update! However, I am not sure how to make two
>> columns in the CollectionsAdmin table without two functions.
>>
>> class CollectionAdmin(self, obj):
>> list_display = ('get_field_1', 'get_field_2', )
>>
>> def get_field_1(self, obj):
>> tempstr = ""
>> documents = obj.document.all()
>> for d in documents:
>> tempstr = tempstr + d.field_1
>>return tempstr
>>
>> def get_field_2(self, obj):
>> tempstr = ""
>> documents = obj.document.all()
>> for d in documents:
>>tempstr = tempstr + d.field_2
>> return tempstr
>>
>> Mark
>>
>> On Sat, Dec 9, 2017 at 9:14 AM, Mark Phillips > > wrote:
>>
>>> Constantine,
>>>
>>> Thanks for the link and update! However, I am not sure how to make two
>>> columns in the CollectionsAdmin table without two functions.
>>>
>>> class COllectionAdmin(self, obj):
>>> list_display =
>>>
>>> On Sat, Dec 9, 2017 at 8:53 AM, Constantine Covtushenko <
>>> constantine@gmail.com> wrote:
>>>
>>>> Hi Mark,
>>>>
>>>> You should not create 2 methods.
>>>> Just change that first to be like:
>>>>
>>>> return obj.document.all().values_list('field_1', 'field_2')
>>>>
>>>> With this you will get QuerySet of tuples, like
>>>> 
>>>>
>>>> I believe it should solve your problem.
>>>>
>>>> Also for more references about values_list, check following
>>>> documentation page:
>>>> https://docs.djangoproject.com/en/2.0/ref/models/querysets/#values-list
>>>>
>>>> Regards,
>>>> Constantine C.
>>>>
>>>> On Sat, Dec 9, 2017 at 12:41 AM, Mark Phillips <
>>>> m...@phillipsmarketing.biz> wrote:
>>>>
>>>>> The point of the queries is to get information about the underlying
>>>>> Documents in each Collection, and display it in the admin page. For
>>>>> example, title is one attribute, but there are also other that I want to
>>>>> display.
>>>>>
>>>>> Your idea obj.document.all().values_list('title', flat=True) makes a
>>>>> lot of sense - Thanks!
>>>>>
>>>>> Now, a bigger question. Say I have two fields in Documents that I want
>>>>> to display side by side in a table in the Collection admin page. I would
>>>>> have two entries in the list_display:
>>>>>
>>>>> list_display = ('get_field_1', 'get_field_2', )
>>>>>
>>>>> and two functions, and each one calls obj.document.all(), which
>>>>> returns a query set of Documents in this particular Collection.
>>>>>
>>>>> def get_field_1(self, obj):
>>>>> tempstr = ""
>>>>> documents = obj.document.all()
>>>>> for d in documents:
>>>>> tempstr = tempstr + d.field_1
>>>>>     return tempstr
>>>>>
>>>>> def get_field_2(self, obj):
>>>>> tempstr = ""
>>>>> documents = obj.document.all()
>>>>> for d in documents:
>>>>> tempstr = tempstr + d.field_2
>>>>> return tempstr
>>>>>
>>>>> These two "list of fields

Re: context must be a dict rather than Context.

2017-12-12 Thread Constantine Covtushenko
Hi Al,

I believe that an error you mentioned is thrown from line:

html = t.render(c)

As said in the error: context must be a dict
So just change

c = template.Context({'now': now})
to be
c = {'now': now}

For more information please check that documentation page
<https://docs.djangoproject.com/en/2.0/topics/templates/#django.template.backends.base.Template.render>

I hope that makes sense.

Regards,
Constantine C.

On Tue, Dec 12, 2017 at 6:25 AM, Al Scham  wrote:

> *Hi,*
>
> *Im a new user going through this tutorial at OverIQ
> : https://overiq.com/django/1.10/loading-templates-in-django
> <https://overiq.com/django/1.10/loading-templates-in-django>*
>
> *I've followed the instructions to the letter but it keep throwing the
> Typeerror you see in the subject.*
>
> *Here is a copy paist of my views :*
>
> from django.shortcuts import render
> from django.http import HttpResponse
> from django import template
> import datetime
>
> def index(request):
> return HttpResponse("Hello Django")
>
> def today_is(request):
> now = datetime.datetime.now()
> t = template.loader.get_template('blog/datetime.html')
> c = template.Context({'now': now})
> html = t.render(c)
> return HttpResponse(html)
>
> *and here is a copy paist of my template:*
>
> 
> 
> 
> 
> Current Time
> 
> 
>
> {#This is a comment #}
> {check the existence of now variable in the template using if tag #}
> {% if now %}
> Current date and time is {{ now }}
> {% else %}
> now variable is not available
> {% endif %}
>
> 
> 
>
> *Any help would be greatly appreciated.*
>
> *Thanks*
> *Allon*
>
>
> --
> 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/67a732ee-ba22-4386-9241-1bd6c362885d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/67a732ee-ba22-4386-9241-1bd6c362885d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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


Re: Multiple roles assign to user in djnago

2017-12-19 Thread Constantine Covtushenko
Hi Ketul,

Did you read that <https://docs.djangoproject.com/en/2.0/topics/auth/>
django documentation?
There you can find all about users, their roles/groups and permissions.

Also can you please elaborate what do you mean under `admin panel`?
Is it just a reference to admin site?

Does it make sense?

Regards,
Constantine C.

On Mon, Dec 18, 2017 at 11:38 PM, Ketul Suthar  wrote:

> I have admin who can create User and Manager
>
> User (id, name, password,role)
> Manager (id, name, password,role)
>
>
> So how can i achieve using admin panel in djnago ?
>
> for that I have to extend User model or create other model ?
>
>
> Can I use same model for User and Manager ? If the i have to add role
> field hoe can I add to User model ?
>
> And all this thing I have to handle from Django admin side how can I
> achieve it ?
>
> --
> 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/870fe422-9be6-4e88-bd47-2572296c224e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/870fe422-9be6-4e88-bd47-2572296c224e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boWm3zNQF6%2BWtQ4hvKCM25bF-rxgLixZmWhX5yVrra-%2BOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple roles assign to user in djnago

2017-12-19 Thread Constantine Covtushenko
Sorry but it is still not clear why you can not use Group for that?
For instance you can create group `Manager` and assign any additional
permissions to it based on your app requirements.

Regarding to User you have 2 options here as said on this page
<https://docs.djangoproject.com/en/2.0/topics/auth/customizing/>
> You can extend
<https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#extending-user>
the
default User model, or substitute
<https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#auth-custom-user>
a
completely customized model.

this is a preferable way to do it.

I hope it make sense to you.

Regards,
Constantine C.

On Tue, Dec 19, 2017 at 9:46 AM, Ketul Suthar  wrote:

> Yes. But I want to  assign role to user as normal user and manager based
> on selection from drop down in admin site and also add new field role_id in
> auth_user table
>
> On Dec 19, 2017 8:13 PM, "Constantine Covtushenko" <
> constantine@gmail.com> wrote:
>
>> Hi Ketul,
>>
>> Did you read that <https://docs.djangoproject.com/en/2.0/topics/auth/>
>> django documentation?
>> There you can find all about users, their roles/groups and permissions.
>>
>> Also can you please elaborate what do you mean under `admin panel`?
>> Is it just a reference to admin site?
>>
>> Does it make sense?
>>
>> Regards,
>> Constantine C.
>>
>> On Mon, Dec 18, 2017 at 11:38 PM, Ketul Suthar 
>> wrote:
>>
>>> I have admin who can create User and Manager
>>>
>>> User (id, name, password,role)
>>> Manager (id, name, password,role)
>>>
>>>
>>> So how can i achieve using admin panel in djnago ?
>>>
>>> for that I have to extend User model or create other model ?
>>>
>>>
>>> Can I use same model for User and Manager ? If the i have to add role
>>> field hoe can I add to User model ?
>>>
>>> And all this thing I have to handle from Django admin side how can I
>>> achieve it ?
>>>
>>> --
>>> 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/ms
>>> gid/django-users/870fe422-9be6-4e88-bd47-2572296c224e%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/870fe422-9be6-4e88-bd47-2572296c224e%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Sincerely yours,
>> Constantine C
>>
>> --
>> 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/ms
>> gid/django-users/CAK52boWm3zNQF6%2BWtQ4hvKCM25bF-rxgLixZmWhX
>> 5yVrra-%2BOQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAK52boWm3zNQF6%2BWtQ4hvKCM25bF-rxgLixZmWhX5yVrra-%2BOQ%40mail.gmail.com?utm_medium=email&utm_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/CANuqdaWH5UoP2TCxOOr8mVDjQ%2B%
> 3DJzap0kAsPS0863O7yOVOxiA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CANuqdaWH5UoP2TCxOOr8mVDjQ%2B%3DJzap0kAsPS0863O7yOVOxiA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boX%2BzBAUO5d6M5dncKUytPQDA_4F7w%2BFgRnnxHa0NAn2xw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Links to comment function in the backend are wrong

2017-12-19 Thread Constantine Covtushenko
Hi Jan,

I would suggest to change python version on new server to be the same as on
your previous server.
Sach an option should be available.
Is it a kind of PAAS service in the cloud? If yes, there should be
documentation how to do that.

Does it make any sense?

Regards,
Constantine C.

On Tue, Dec 19, 2017 at 10:53 AM, Jan Kout  wrote:

> Hello,
>
> after transfer of my website to a server with a newer version of python
> the links to comment function in the backend does not work any more. I
> don't really know django vera well and unfortunatelly I don't know how to
> fix it. I guess that I could set something in a file but I don't know what
> exactly. Maybe I should upgrade the django installation too.
>
> Could somebody help me, please? Thank you.
>
> Best wishes, Jan
>
> --
> 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/92b0b670-3acb-4d8a-bbb3-085488c698bc%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/92b0b670-3acb-4d8a-bbb3-085488c698bc%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boV2kBPS6WWqfrWUyR3-XmG%3DZkFXYsq003T3vGW5cWGA%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: send / receive data securely from a wifi module... how many steps?

2017-12-19 Thread Constantine Covtushenko
Hi,

As soon as I understand you need to enable django authentication for you
applications.
Please check following django documentation page.
<https://docs.djangoproject.com/en/2.0/topics/auth/>


Regards,
Constantine C.

On Fri, Dec 15, 2017 at 11:16 AM, R design 
wrote:

> I've built a couple of basic django projects and would now like to add
> User Authentication and SSL.
>
> The objective is to be able to securely send data to/from a WIFI module
> (ATWINC1500) <=> Django's database through normal http channels (no need
> for anything fancy).
>
> Can user login be compressed into the same http GET data or POST data? Or
> must one perform a login before afterwards sending the GET/POST?
>
> Will the user session remain open afterwards and, if so, for how long?
>
> Would anyone explain the steps involved?
>
> Any observations 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/ba213547-7d4f-4fb7-871e-28c24e8a63a1%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ba213547-7d4f-4fb7-871e-28c24e8a63a1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

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