Accessing child relations when overriding save()

2019-02-10 Thread Nick Emery
I am trying to wrap up my first app using Django (specifically Django Rest 
Framework which may change the save behavior), but have run into an issue 
that I haven't been able to solve for about 10 hours now.

I am trying to override the save() method of a model to modify a field on a 
bunch of child objects when it is created; however, I can't figure out *any* 
way 
get the objects or ids for the children.

My code looks something like:
class Parent(models.Model):
   """When I create this, I want the children to be modified."""
   def save(self, *args, **kwargs):
   if not self.pk:
   self._begin(*args, **kwargs)
   else:
   super(Parent, self).save(*args, **kwargs)

def _begin(self, *args, **kwargs):
   super(Parent, self).save(*args, **kwargs)
   print(self.child_set.all())  # --> This gives: ""
   for i in self.child_set.all():
   i.last_name = self.last_name
   i.save()

last_name = models.CharField(max_length=100)


class Child:
   parent = models.ForeignKey(
   'Parent',
   on_delete=models.SET_NULL,
   null=True,
)
   last_name = models.CharField(max_length=100)

ANY way to modify the children when the parent is saved would be a life 
saver (even if hacky or sub-optimal).

-- 
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/24c7156b-6873-4cd3-952e-dc819fa72be0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing child relations when overriding save()

2019-02-10 Thread Shashank Singh
Override the save() of the child?

On Sun, 10 Feb, 2019, 7:04 PM Nick Emery  I am trying to wrap up my first app using Django (specifically Django
> Rest Framework which may change the save behavior), but have run into an
> issue that I haven't been able to solve for about 10 hours now.
>
> I am trying to override the save() method of a model to modify a field on
> a bunch of child objects when it is created; however, I can't figure out
> *any* way get the objects or ids for the children.
>
> My code looks something like:
> class Parent(models.Model):
>"""When I create this, I want the children to be modified."""
>def save(self, *args, **kwargs):
>if not self.pk:
>self._begin(*args, **kwargs)
>else:
>super(Parent, self).save(*args, **kwargs)
>
> def _begin(self, *args, **kwargs):
>super(Parent, self).save(*args, **kwargs)
>print(self.child_set.all())  # --> This gives: ""
>for i in self.child_set.all():
>i.last_name = self.last_name
>i.save()
>
> last_name = models.CharField(max_length=100)
>
>
> class Child:
>parent = models.ForeignKey(
>'Parent',
>on_delete=models.SET_NULL,
>null=True,
> )
>last_name = models.CharField(max_length=100)
>
> ANY way to modify the children when the parent is saved would be a life
> saver (even if hacky or sub-optimal).
>
> --
> 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/24c7156b-6873-4cd3-952e-dc819fa72be0%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/CAD-d1sb3WVXk262-dfKuJUZ_9Kj49NDzShyv5ivL_SRrAiaMmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing child relations when overriding save()

2019-02-10 Thread Nick Emery
Tried this too but save() never actually gets called on the child (it seems 
that the foreign key field of the child is updated at the database level 
and never goes through the Django orm Child).

On Sunday, February 10, 2019 at 8:37:54 AM UTC-5, Shashank Singh wrote:
>
> Override the save() of the child?
>
> On Sun, 10 Feb, 2019, 7:04 PM Nick Emery  
> wrote:
>
>> I am trying to wrap up my first app using Django (specifically Django 
>> Rest Framework which may change the save behavior), but have run into an 
>> issue that I haven't been able to solve for about 10 hours now.
>>
>> I am trying to override the save() method of a model to modify a field on 
>> a bunch of child objects when it is created; however, I can't figure out 
>> *any* way get the objects or ids for the children.
>>
>> My code looks something like:
>> class Parent(models.Model):
>>"""When I create this, I want the children to be modified."""
>>def save(self, *args, **kwargs):
>>if not self.pk:
>>self._begin(*args, **kwargs)
>>else:
>>super(Parent, self).save(*args, **kwargs)
>>
>> def _begin(self, *args, **kwargs):
>>super(Parent, self).save(*args, **kwargs)
>>print(self.child_set.all())  # --> This gives: ""
>>for i in self.child_set.all():
>>i.last_name = self.last_name
>>i.save()
>>
>> last_name = models.CharField(max_length=100)
>>
>>
>> class Child:
>>parent = models.ForeignKey(
>>'Parent',
>>on_delete=models.SET_NULL,
>>null=True,
>> )
>>last_name = models.CharField(max_length=100)
>>
>> ANY way to modify the children when the parent is saved would be a life 
>> saver (even if hacky or sub-optimal).
>>
>> -- 
>> 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/24c7156b-6873-4cd3-952e-dc819fa72be0%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/8dca6561-aea1-492d-b209-a9767ce30bd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing child relations when overriding save()

2019-02-10 Thread Shashank Singh
When do you create child objects??

On Sun, 10 Feb, 2019, 9:17 PM Nick Emery  Tried this too but save() never actually gets called on the child (it
> seems that the foreign key field of the child is updated at the database
> level and never goes through the Django orm Child).
>
> On Sunday, February 10, 2019 at 8:37:54 AM UTC-5, Shashank Singh wrote:
>>
>> Override the save() of the child?
>>
>> On Sun, 10 Feb, 2019, 7:04 PM Nick Emery >
>>> I am trying to wrap up my first app using Django (specifically Django
>>> Rest Framework which may change the save behavior), but have run into
>>> an issue that I haven't been able to solve for about 10 hours now.
>>>
>>> I am trying to override the save() method of a model to modify a field
>>> on a bunch of child objects when it is created; however, I can't figure out
>>> *any* way get the objects or ids for the children.
>>>
>>> My code looks something like:
>>> class Parent(models.Model):
>>>"""When I create this, I want the children to be modified."""
>>>def save(self, *args, **kwargs):
>>>if not self.pk:
>>>self._begin(*args, **kwargs)
>>>else:
>>>super(Parent, self).save(*args, **kwargs)
>>>
>>> def _begin(self, *args, **kwargs):
>>>super(Parent, self).save(*args, **kwargs)
>>>print(self.child_set.all())  # --> This gives: ""
>>>for i in self.child_set.all():
>>>i.last_name = self.last_name
>>>i.save()
>>>
>>> last_name = models.CharField(max_length=100)
>>>
>>>
>>> class Child:
>>>parent = models.ForeignKey(
>>>'Parent',
>>>on_delete=models.SET_NULL,
>>>null=True,
>>> )
>>>last_name = models.CharField(max_length=100)
>>>
>>> ANY way to modify the children when the parent is saved would be a life
>>> saver (even if hacky or sub-optimal).
>>>
>>> --
>>> 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/24c7156b-6873-4cd3-952e-dc819fa72be0%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/8dca6561-aea1-492d-b209-a9767ce30bd0%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/CAD-d1saAWzXP02mpHNhPYA7M%3D%3DKPOJ1MesROScsLLx2JpLOg_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing child relations when overriding save()

2019-02-10 Thread Shashank Singh
And how?

On Sun, 10 Feb, 2019, 9:23 PM Shashank Singh  When do you create child objects??
>
> On Sun, 10 Feb, 2019, 9:17 PM Nick Emery 
>> Tried this too but save() never actually gets called on the child (it
>> seems that the foreign key field of the child is updated at the database
>> level and never goes through the Django orm Child).
>>
>> On Sunday, February 10, 2019 at 8:37:54 AM UTC-5, Shashank Singh wrote:
>>>
>>> Override the save() of the child?
>>>
>>> On Sun, 10 Feb, 2019, 7:04 PM Nick Emery >>
 I am trying to wrap up my first app using Django (specifically Django
 Rest Framework which may change the save behavior), but have run into
 an issue that I haven't been able to solve for about 10 hours now.

 I am trying to override the save() method of a model to modify a field
 on a bunch of child objects when it is created; however, I can't figure out
 *any* way get the objects or ids for the children.

 My code looks something like:
 class Parent(models.Model):
"""When I create this, I want the children to be modified."""
def save(self, *args, **kwargs):
if not self.pk:
self._begin(*args, **kwargs)
else:
super(Parent, self).save(*args, **kwargs)

 def _begin(self, *args, **kwargs):
super(Parent, self).save(*args, **kwargs)
print(self.child_set.all())  # --> This gives: ""
for i in self.child_set.all():
i.last_name = self.last_name
i.save()

 last_name = models.CharField(max_length=100)


 class Child:
parent = models.ForeignKey(
'Parent',
on_delete=models.SET_NULL,
null=True,
 )
last_name = models.CharField(max_length=100)

 ANY way to modify the children when the parent is saved would be a life
 saver (even if hacky or sub-optimal).

 --
 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/24c7156b-6873-4cd3-952e-dc819fa72be0%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/8dca6561-aea1-492d-b209-a9767ce30bd0%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/CAD-d1samXw4%2BQqO-hnUw020WjNtDRwoSYxPxFBCBhN%3DP6%3D_ucQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Password Policy Adherence. Cannot use the passwords used before

2019-02-10 Thread Simon A
Hi guys,

Please correct me if my thought process is wrong. 

Here is what I am trying to achieve, in order for me to save the password 
generated before saving the new password to the system, I have to somehow 
override the existing process. Which is by subclassing the 
PasswordChangeView. As I check the available methods that I can override, I 
got more confused because none of these methods seem to retrieve the 
password from the form, then hash it. then store the hashed password in the 
User's profile. Where does this actually happen? 

I looked at 
here 
http://ccbv.co.uk/projects/Django/2.1/django.contrib.auth.views/PasswordChangeView/
 
and 
http://ccbv.co.uk/projects/Django/2.1/django.contrib.auth.views/PasswordContextMixin/
 
to identify where does the process of hashing and saving happen but it just 
doesn't make sense to me at the moment. I'm sorry I'm not trying to be 
spoon fed here but just a bit lost.

Any feedback would be appreciated.

Thank you,
Simon

On Sunday, February 10, 2019 at 6:28:10 AM UTC+8, Simon A wrote:
>
> @Jason, yes I believe I do need to research further when that action 
> happens. the point where the password is hashed and stored in the User 
> table. I'll continue to work on it.
>
> @James, currently the requirements are non debatable for us developers in 
> the company. The security team implemented the guidelines and by any means, 
> they have to be implemented. (Even though the company apps don't even 
> follow the policies!) I believe it's just additional work for developers, 
> and makes the development time longer which equates to less value to 
> customers. But I do appreciate the points you provided. When I have the 
> chance to have a discussion with the security team, I will definitely bring 
> up these points.
>
> On Fri, Feb 8, 2019 at 11:19 PM Matthew Pava  wrote:
>
>> I completely support this NIST policy, James.  Unfortunately, the PCI 
>> Security Standards Council does not support this policy at this time.  In 
>> order for a company to be PCI compliant, users must change their passwords 
>> every three months.  PCI compliance is essential for companies to adhere to 
>> when they are processing credit cards.  There are ways around the 
>> requirements; companies could basically out-source credit card processing 
>> to other companies such as Stripe or Square, but they need to know what 
>> they are doing to maintain compliance.
>>
>>  
>>
>>
>> https://www.pcisecuritystandards.org/documents/Payment-Data-Security-Essential-Strong-Passwords.pdf?agreement=true&time=1549638814227
>>
>>  
>>
>>  
>>
>>  
>>
>> *From:* django-users@googlegroups.com [mailto:
>> django-users@googlegroups.com] *On Behalf Of *James Bennett
>> *Sent:* Friday, February 8, 2019 9:00 AM
>> *To:* django-users@googlegroups.com
>> *Subject:* Re: Password Policy Adherence. Cannot use the passwords used 
>> before
>>
>>  
>>
>> I'm going to suggest you step back and consider whether the policies you 
>> want to implement are good policies. A good, solidly-researched set of 
>> recommendations is NIST SP800-63B:
>>
>>  
>>
>> https://pages.nist.gov/800-63-3/sp800-63b.html
>>
>>  
>>
>> In particular, NIST suggests the following:
>>
>>  
>>
>> * Do not use a policy which automatically "expires" passwords and forces 
>> users to change them periodically. Only force a password change when you 
>> have evidence that a password has been compromised.
>>
>> * Do not try to impose artificial "complexity" rules (like requiring a 
>> mix of uppercase/lowercase, numbers and symbols).
>>
>> * When a user changes their password, compare it against lists of 
>> known-compromised passwords.
>>
>>  
>>
>> Forcing users to change their passwords on a set schedule just encourages 
>> them to choose weak passwords that are easy to remember. If you force me to 
>> change my password every three months, for example, here's what I'll do:
>>
>>  
>>
>> * P@ssword!2019_1
>>
>> * P@ssword!2019_2
>>
>> * P@ssword!2019_3
>>
>> * P@ssword!2019_4
>>
>>  
>>
>> These passwords are all different from each other, and they each contain 
>> at least one uppercase and one lowercase letter, at least one number and at 
>> least one symbol. They're also terrible passwords that would probably get 
>> cracked within minutes, if not seconds, by any good automated cracker.
>>
>> That's a year's worth of passwords, each of which is different from the 
>> last, each contains one 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAL13Cg9Xi7QdCCffqROi_FjLzKimtWYBR%3DusMxf6ihf_E6%3D-9A%40mail.gmail.com
>>  
>> 

Re: Accessing child relations when overriding save()

2019-02-10 Thread Nick Emery
The child objects are created separately beforehand with NULL parents (they 
don't have to have parents, they can be orphans). One other thing I noticed 
is that looking at the SQL statements executed by my app I can't even see 
the UPDATE on the foreign keys of the children (even though I KNOW it's 
happening because I can go look at those children and see that they do get 
updated). It's as if Django doesn't even know about this at all.

On Sunday, February 10, 2019 at 10:54:10 AM UTC-5, Shashank Singh wrote:
>
> And how?
>
> On Sun, 10 Feb, 2019, 9:23 PM Shashank Singh   wrote:
>
>> When do you create child objects??
>>
>> On Sun, 10 Feb, 2019, 9:17 PM Nick Emery >  wrote:
>>
>>> Tried this too but save() never actually gets called on the child (it 
>>> seems that the foreign key field of the child is updated at the database 
>>> level and never goes through the Django orm Child).
>>>
>>> On Sunday, February 10, 2019 at 8:37:54 AM UTC-5, Shashank Singh wrote:

 Override the save() of the child?

 On Sun, 10 Feb, 2019, 7:04 PM Nick Emery >>>
> I am trying to wrap up my first app using Django (specifically Django 
> Rest Framework which may change the save behavior), but have run into 
> an issue that I haven't been able to solve for about 10 hours now.
>
> I am trying to override the save() method of a model to modify a field 
> on a bunch of child objects when it is created; however, I can't figure 
> out 
> *any* way get the objects or ids for the children.
>
> My code looks something like:
> class Parent(models.Model):
>"""When I create this, I want the children to be modified."""
>def save(self, *args, **kwargs):
>if not self.pk:
>self._begin(*args, **kwargs)
>else:
>super(Parent, self).save(*args, **kwargs)
>
> def _begin(self, *args, **kwargs):
>super(Parent, self).save(*args, **kwargs)
>print(self.child_set.all())  # --> This gives: ""
>for i in self.child_set.all():
>i.last_name = self.last_name
>i.save()
>
> last_name = models.CharField(max_length=100)
>
>
> class Child:
>parent = models.ForeignKey(
>'Parent',
>on_delete=models.SET_NULL,
>null=True,
> )
>last_name = models.CharField(max_length=100)
>
> ANY way to modify the children when the parent is saved would be a 
> life saver (even if hacky or sub-optimal).
>
> -- 
> 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/24c7156b-6873-4cd3-952e-dc819fa72be0%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...@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/8dca6561-aea1-492d-b209-a9767ce30bd0%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/32b133b9-9649-4490-afb9-87beb07af1e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Inlineformset parameter for a queryset

2019-02-10 Thread Gerson David Vizquel Alemán
Hello I resort to this medium because I have already invested a lot of time 
looking for the solution and I can not find it.

I have two questions, one of the two will help me to solve an approach that 
I have:
 1.- How can I pass parameters to the inlineformset?
 2.- How can I read the value of a field of the parent form from the 
inlineformset?

The issue is that I need to filter the queryset of a select field in the 
inlineformset, with a value that happened in the url or that it places 
hidden in the parent form.

First of all, 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/3178394c-3e82-452d-badf-6a0aee7e8170%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing child relations when overriding save()

2019-02-10 Thread Nick Emery
UPDATE: Finally figured it out! I ultimately did this by overriding 
`perform_create()` in my [Django Rest Framework 
view](https://www.django-rest-framework.org/api-guide/generic-views/) and 
making my changes after saving the object.

On Sunday, February 10, 2019 at 8:34:44 AM UTC-5, Nick Emery wrote:
>
> I am trying to wrap up my first app using Django (specifically Django 
> Rest Framework which may change the save behavior), but have run into an 
> issue that I haven't been able to solve for about 10 hours now.
>
> I am trying to override the save() method of a model to modify a field on 
> a bunch of child objects when it is created; however, I can't figure out 
> *any* way get the objects or ids for the children.
>
> My code looks something like:
> class Parent(models.Model):
>"""When I create this, I want the children to be modified."""
>def save(self, *args, **kwargs):
>if not self.pk:
>self._begin(*args, **kwargs)
>else:
>super(Parent, self).save(*args, **kwargs)
>
> def _begin(self, *args, **kwargs):
>super(Parent, self).save(*args, **kwargs)
>print(self.child_set.all())  # --> This gives: ""
>for i in self.child_set.all():
>i.last_name = self.last_name
>i.save()
>
> last_name = models.CharField(max_length=100)
>
>
> class Child:
>parent = models.ForeignKey(
>'Parent',
>on_delete=models.SET_NULL,
>null=True,
> )
>last_name = models.CharField(max_length=100)
>
> ANY way to modify the children when the parent is saved would be a life 
> saver (even if hacky or sub-optimal).
>

-- 
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/fb550843-22ae-46f2-9236-c44414c5eb25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Password Policy Adherence. Cannot use the passwords used before

2019-02-10 Thread Jason
ClassyCBV doesn't contain everything in django, so that is probably related 
to your confusion.

In classycbv PasswordChangeView's attributes, you can see 
form_class = 
which is what is called in PCV's Post handler 


Now, that form is defined here 
, 
which inherits from SetPasswordForm 
.  
There's two methods inside that class, save, and clean_new_password2 


Since these forms inherit from forms.Form 
, 
they all inherit is_valid, which has this comment:  
"""Return True if the form has no errors, or False otherwise."""
So, what you'll need to do is override that `is_valid` method in your 
custom Form class to do the work for 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/f3380a52-2bdf-4bf3-bc9d-833cefe5d406%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


“python -m django --version” 1.11.18 Cannot update to 2.1

2019-02-10 Thread Dom Delbuco


I'm new to Python and Django, I watched a tutorial that requires me to have 
Django 2.1. When I type in "python -m django --version" - my Ubuntu 
terminal says 1.11.18 But, when I type "django-admin --version" - terminal 
says 2.1 This didn't bother me until I reached part 6 of this series, I'm 
balls deep now with a serious problem I can't figure out. 


I even completely reinstalled my OS, (I was running linux mint, thought 
it'd be easier if I ran Ubuntu) I ran through a myriad of different "fixes" 
I found online, but nothing seemed to fix this. The main issue that I ran 
into from the tutorial is the urls linking, I'm not sure if that helps, but 
it's there. Thanks

And yes, I do have Python 3 installed. 


-- 
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/131bfcbb-3e8b-4ab9-adfb-b4fe991f562b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Admin form_url breakout problem

2019-02-10 Thread Mike Dewhirst

Matthew

I think a workaround would be to reload the admin urls after each Stripe 
transaction. I don't know how to do that after looking at options.py etc.


I know I'm doing something adverse and it is spoiling the admin urls 
because the url in the address bar is correct but the page contents is 
empty. Refresh and shift-refresh doesn't do anything.


Saving a bit of source to reload runserver fixes (works around) the problem.

I'm happy to reveal as much source as necessary if you would like to see 
it and have the time.


Thanks very much for sticking with this

Mike

On 5/02/2019 2:19 am, Matthew Pava wrote:

The flow looks fine.  And when you click refresh on your browser on step 4 does 
the page refresh properly?

Perhaps it's a caching issue.
Are you wrapping the billing_payment_view with admin_view()?
https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls
 --> scroll towards the bottom of that section


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mike Dewhirst
Sent: Sunday, February 3, 2019 1:42 AM
To: django-users@googlegroups.com
Subject: Re: Admin form_url breakout problem

Matthew

I was wrong. I'm still in trouble. I thought it might be an incomplete
transaction so I tried making the the subscription.save() atomic but to
no avail.

Here is what happens ...

1.  Add an ingredient which is payable

2.  Save mixture

3.  SubstanceAdmin.change_view() establishes ...

      subscription = None
      if ingredient.is_payable():
      get or create a subscription record and populate it with fee,
gst etc.
      if the subscription.token field is blank (ie not paid):
      call billing_payment_view() which interfaces with Stripe
via a js popup and
      a) gets a token in a hidden field
      b) calls Stripe.charge(token) and gets a json charge
record back
                  c) populates the subscription.token field
      d) saves the subscription record
      e) creates a receipt record
      f) sends an email receipt
      g) puts thank you text and mixture url into context dict
      h) calls billing_success_view(request, context) to
display success
     message including link back to mixture
      return super(SubstanceAdmin, self).change_view()

4.  On clicking the back-to-the-mixture link in success.html, the Admin
brings
      up the Change Substance page without error but which is blank below the
      "Change Substance" heading. At that time the displayed URL in the
address
      bar is exactly correct.

5.  If the dev server reloads the page will paint properly if refreshed.

Theory:

The subscription record has been saved but not in a way which is visible
yet thereby confusing change_view() into thinking the token field is blank.

In other words the transaction needs to be committed
pre-billing_success_view()

In testing this it sadly this makes no difference.

Mike


On 2/02/2019 6:06 pm, Mike Dewhirst wrote:

I think I know. Don't waste time on this. I'll report back later.

Mike

On 2/02/2019 3:27 pm, Mike Dewhirst wrote:

I thought it was fixed but not so. It works perfectly *only* if the
dev server reloads after all the work and prior to clicking the link
on the success.html template back to the mixture (the substance with
ingredients).

I tried a workaround of making the link point to the substances list
page first. No difference. All substance pages come up blank.

When I reported earlier that it was working I must have changed some
text in a view to improve the screen wording and on saving the dev
server would have reloaded itself and that hid the problem.

The admin url is correct  ...

http://localhost:8000/admin/substance/substance/1442/change/

... but that refuses to display. There is no delay, no spinner. The
server console window shows nothing.

Not sure where to start looking.

Maybe something has corrupted Django's in-memory list of url patterns?

Is it caching?

Thanks for any non-javascript hints

Mike

On 30/01/2019 5:13 pm, Mike Dewhirst wrote:

Matthew

I looked for preventDefault and found it in lots of javascript
scripts. So I decided instead to look at my python code which is
slightly easier for me to understand. I sort of refactored it and
cut large swags out to simplify and inserted lots of print
statements. Then I thought I'd better read your advice again and try
harder to understand it.

The bit which made sense to me was ...

'let the admin handle it from there'

... I noticed that I was returning the billing payment_view. As soon
as I removed that 'return' and let the change_view return the super
call it started working.

Thank you very much for persisting with me.

The Admin is fabulous! Nobel prize for something is warranted :)

Much appreciated

Mike

On 29/01/2019 2:31 am, Matthew Pava wrote:

Hi Mike,
When Stripe processes the 

Re: Accessing child relations when overriding save()

2019-02-10 Thread Mike Dewhirst

On 10/02/2019 6:22 pm, Nick Emery wrote:
I am trying to wrap up my first app using Django (specifically Django 
Rest Framework which may change the save behavior), but have run into 
an issue that I haven't been able to solve for about 10 hours now.


I am trying to override the save() method of a model to modify a field 
on a bunch of child objects when it is created; however, I can't 
figure out /any/ way get the objects or ids for the children.


My code looks something like:


I usually have a couple of methods to simplify save operations like this ...

def save(self, *args, **kwargs):
    results = self._pre_save(self)
    super(Parent, self).save(*args, **kwargs)
    self._post_save(self, results)

Much easier for me to "see" what I'm doing.

In your case if orphans exist, how do you identify them as now related 
to a new Parent? Perhaps a query looking for parent=None.


From what I understand of your use case you would need to select a 
Child when creating a Parent. That sounds like a field widget to perform 
that query before the Parent is first saved. If so, the Child object 
would be available to _pre_save() but the Parent still does not yet 
exist and Parent.id is still None so you can't populate the Child FK.


Parent.id is however available to _post_save() so if the Child object is 
passed from _pre_save() via results (above) then _post_save can populate 
its FK with self and just save the Child object to complete the deal.


The relationship is the foreign key which means the Child can have only 
one Parent which doesn't yet exist. So it feels like a sky hook.


Parents and children (as data) are person objects with virtually 
identical attributes. The interesting information is in the relationship 
for which a foreign key seems too restrictive. Have you considered a 
"through" table thus making a many-to-many relationship? That table can 
carry heaps of information about the relationship and is very flexible. 
For example, the child can now have two parents.


When a "through" record is created to establish a relationship 
(selectable from a choices list), both parent and child already exist 
which lets you delegate a fair bit of processing to the "though" model 
save() method which in real world timing is probably where it belongs. I 
prefer it because I can use queries rather than widgets.


Not sure if this helps

Mike


|
classParent(models.Model):
"""When I create this, I want the children to be modified."""
defsave(self,*args,**kwargs):
ifnotself.pk :
self._begin(*args,**kwargs)
else:
super(Parent,self).save(*args,**kwargs)

def_begin(self,*args,**kwargs):
super(Parent,self).save(*args,**kwargs)
print(self.child_set.all())# --> This gives: ""
   for i in self.child_set.all():
       i.last_name = self.last_name
       i.save()

last_name =models.CharField(max_length=100)


classChild:
   parent =models.ForeignKey(
'Parent',
       on_delete=models.SET_NULL,
null=True,
)
 last_name =models.CharField(max_length=100)
|

ANY way to modify the children when the parent is saved would be a 
life saver (even if hacky or sub-optimal).

--
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/24c7156b-6873-4cd3-952e-dc819fa72be0%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/16aac83a-29f5-3a6d-f4e9-431469f56689%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: “python -m django --version” 1.11.18 Cannot update to 2.1

2019-02-10 Thread JP Smith
I know that you are new so, I don't want to overwhelm you.  One thing that
you might want to look into is pip, which is a package management tool for
python.  This will allow you to install python packages and keep them
up-to-date.

The if you want to take a more manual approach, you could download a gzip
file from the Django Project web site and install the most recent 2.1
version there.

What I would suggest is that, when you get a better understanding of Django
and Python, you can start using virtualenvwrapper to set up your
development environment(s).  There is a slight learning curve but, it
allows you to have setups that keep you from hosing up your system by
restricting your package installs to the development environment, versus
the system at-large.

You can search on pip and virtualenvwrapper to get an an idea on what each
of these does.

On Sun, Feb 10, 2019 at 8:44 PM Dom Delbuco  wrote:

> I'm new to Python and Django, I watched a tutorial that requires me to
> have Django 2.1. When I type in "python -m django --version" - my Ubuntu
> terminal says 1.11.18 But, when I type "django-admin --version" - terminal
> says 2.1 This didn't bother me until I reached part 6 of this series, I'm
> balls deep now with a serious problem I can't figure out.
>
>
> I even completely reinstalled my OS, (I was running linux mint, thought
> it'd be easier if I ran Ubuntu) I ran through a myriad of different "fixes"
> I found online, but nothing seemed to fix this. The main issue that I ran
> into from the tutorial is the urls linking, I'm not sure if that helps, but
> it's there. Thanks
>
> And yes, I do have Python 3 installed.
>
>
> --
> 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/131bfcbb-3e8b-4ab9-adfb-b4fe991f562b%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/CAD6X1ZUEv1acTHE2JAtAcFFqpW7fC6hrS_MSCFdAofpvqaUR1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Password Policy Adherence. Cannot use the passwords used before

2019-02-10 Thread Simon A
Hi Jason,

Thank you for  your response, really appreciate the help. I was working on 
your suggestion but then stumbled across django-password-validators which 
seems to do the required task for me. For now I will go with this one. But 
I will surely include the github for django when learning things to better 
understand how some magis work.

Kind Regards,
Simon Arriola

On Monday, February 11, 2019 at 9:00:57 AM UTC+8, Jason wrote:
>
> ClassyCBV doesn't contain everything in django, so that is probably 
> related to your confusion.
>
> In classycbv PasswordChangeView's attributes, you can see 
> form_class = 
> which is what is called in PCV's Post handler 
> 
>
> Now, that form is defined here 
> ,
>  
> which inherits from SetPasswordForm 
> .
>   
> There's two methods inside that class, save, and clean_new_password2 
> 
>
> Since these forms inherit from forms.Form 
> , 
> they all inherit is_valid, which has this comment:  
> """Return True if the form has no errors, or False otherwise."""
> So, what you'll need to do is override that `is_valid` method in your 
> custom Form class to do the work for 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/a6ac258f-b509-4df0-87b7-998dbe42ae72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: “python -m django --version” 1.11.18 Cannot update to 2.1

2019-02-10 Thread sachin thakur
Uninstall the 1.11.18 and install 2.1


On Mon 11 Feb, 2019, 9:08 AM JP Smith  I know that you are new so, I don't want to overwhelm you.  One thing that
> you might want to look into is pip, which is a package management tool for
> python.  This will allow you to install python packages and keep them
> up-to-date.
>
> The if you want to take a more manual approach, you could download a gzip
> file from the Django Project web site and install the most recent 2.1
> version there.
>
> What I would suggest is that, when you get a better understanding of
> Django and Python, you can start using virtualenvwrapper to set up your
> development environment(s).  There is a slight learning curve but, it
> allows you to have setups that keep you from hosing up your system by
> restricting your package installs to the development environment, versus
> the system at-large.
>
> You can search on pip and virtualenvwrapper to get an an idea on what each
> of these does.
>
> On Sun, Feb 10, 2019 at 8:44 PM Dom Delbuco  wrote:
>
>> I'm new to Python and Django, I watched a tutorial that requires me to
>> have Django 2.1. When I type in "python -m django --version" - my Ubuntu
>> terminal says 1.11.18 But, when I type "django-admin --version" - terminal
>> says 2.1 This didn't bother me until I reached part 6 of this series, I'm
>> balls deep now with a serious problem I can't figure out.
>>
>>
>> I even completely reinstalled my OS, (I was running linux mint, thought
>> it'd be easier if I ran Ubuntu) I ran through a myriad of different "fixes"
>> I found online, but nothing seemed to fix this. The main issue that I ran
>> into from the tutorial is the urls linking, I'm not sure if that helps, but
>> it's there. Thanks
>>
>> And yes, I do have Python 3 installed.
>>
>>
>> --
>> 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/131bfcbb-3e8b-4ab9-adfb-b4fe991f562b%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/CAD6X1ZUEv1acTHE2JAtAcFFqpW7fC6hrS_MSCFdAofpvqaUR1Q%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/CA%2BLmcYsTkDogsxdCVr3A3CHmdScc3sOXpFhkEGodqYAikcveYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Upgrading project from Django 1.11 to 2.1

2019-02-10 Thread Mike Dewhirst

Is it safe/advisable to globally replace

six.text_types(
with
str(

Thanks

Mike

--
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/ac4ffb5c-0e35-07c7-3910-04dd9c88422c%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Upgrading project from Django 1.11 to 2.1

2019-02-10 Thread PARTH PATIL
Six.text_types is used to represent unicode() in python2 and str in python3.
And now you are only using python3, it would be safe to replace it with str()

-- 
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/9b9c5c27-64c2-4af1-9940-716f7ebf5a2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to display file&folder tree using Django. Help, please!

2019-02-10 Thread Derek
There are a number of custom Django apps that can do something like, for 
example:

https://github.com/IMGIITRoorkee/django-filemanager

(or look here  https://djangopackages.org/grids/g/file-managers/ for more)

On Friday, 8 February 2019 14:24:01 UTC+2, Yura wrote:
>
> Hello everyone! I really need help. I’ve got SQL table which contains 
> exhaustive files and folders information and I need to show tree of those 
> files on a website. But not only show, it’s supposed to be interactive, so 
> that a user can scroll, open folders and mark any of the items. 
> I think it might look like an example on the attached picture (or here, 
> example png link: https://yadi.sk/i/H3wzUMt_UmT3AQ ). 
> If someone can give advice how to implement this app in django that would 
> be really helpful, or maybe just any thoughts regarding it, I’d really 
> appreciate 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/0ba8e17c-27dc-4247-9f2d-7227e2c70fdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.