Re: CRUD code feedback

2018-01-27 Thread Akhil Lawrence
I doubt whether you are reading my response properly. Let me reiterate my 
response for you.


*There are two ways to do this. *

*1. You can set the owner as the logged in user by default*
*2. You can provide all possible owners as options and the user can select 
the owner from a dropdown.*

*For case 1, you may not want to display the owner field in frontend. Here 
you can override form_valid and set the owner as logged in user.*

*class CreateDog(CreateView):*
*...*
*def form_valid(self, form):*
*form.instance.owner = self.request.user*
*return super(CreateDog, self).form_valid(form)*

*For more details:*

*https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user
 
*

*http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid
 
*


*For case 2, you need to populate the list of owners by overriding the 
get_initial method.*

*class CreateDog(CreateView):*
*...*
*def get_initial(self):*
*initial_data = super(CreateDog, self).get_initial()*
*initial_data["owner"] = [(x.id , x.name 
) for x in Owner.objects.all()]*
*return initial_data*

*For more details:*

*https://docs.djangoproject.com/en/2.0/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.initial
 
*
*http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#get_initial*
 



if you don't want to show the owner and want to associate the pet with 
owner via backend go for option1 (also note that you may need to remove the 
owner from fields of your createview)
if you want to show a dropdown of possible owners go for option 2.

If you need further assistance, please share your screen via chrome remote 
desktop or something and lets solve it

Thanks.


On Sunday, 28 January 2018 12:29:58 UTC+5:30, tangoward15 wrote:
>
> Sorry for being a drag, I tried this code:
>
> class CreateDog(CreateView):
> template_name = 'dogs_cats/create_dog.html'
> model = Dog
> fields = ('name', 'bday', 'owner')
>
> def get_initial(self):
> initial_data = super(CreateDog, self).get_initial()
> initial_data["owner"] = [(self.request.user.id, 
> self.request.user.username)]
> return initial_data
>
>
> still I am getting the Admin user in the drop down list for owner.
>
> On Sun, Jan 28, 2018 at 2:31 PM, Akhil Lawrence  > wrote:
>
>>
>> override get_initial and set only the logged in user
>>
>> class CreateDog(CreateView):
>> ...
>> def get_initial(self):
>> initial_data = super(CreateDog, self).get_initial()
>> initial_data["owner"] = [(self.request.user.id, 
>> self.request.user.username)]
>> return initial_data
>>
>>
>>
>>
>> On Sunday, 28 January 2018 11:52:31 UTC+5:30, tangoward15 wrote:
>>>
>>> I updated my models. py
>>>
>>> from django.db import models
>>> from django.contrib.auth import get_user_model
>>> from django.contrib.auth.models import User, PermissionsMixin
>>>
>>> # Create your models here.
>>>
>>>
>>> Pet_Owner = get_user_model()
>>>
>>>
>>> class RegisteredUser(User, PermissionsMixin):
>>>
>>> def __str__(self):
>>> return self.username
>>>
>>>
>>> class Dog(models.Model):
>>> name = models.CharField(max_length=40)
>>> bday = models.DateField()
>>> owner = models.ForeignKey(Pet_Owner, related_name='dogs', 
>>> on_delete=models.CASCADE)
>>>
>>> def __str__(self):
>>> return self.name + ' - ' + str(self.owner)
>>>
>>>
>>> class Cat(models.Model):
>>> name = models.CharField(max_length=40)
>>> bday = models.DateField()
>>> owner = models.ForeignKey(Pet_Owner, related_name='cats', 
>>> on_delete=models.CASCADE)
>>>
>>> def __str__(self):
>>> return self.name + ' - ' + str(self.owner)
>>>
>>>
>>> I can see all users as drop down list for owner field using Pet_Owner = 
>>> get_user_model() .Problem is, it shows all the Users in the project not the 
>>> only one who is currently logged in.
>>>
>>> On Sun, Jan 28, 2018 at 2:06 PM, Akhil Lawrence  
>>> wrote:
>>>
 Its the reverse. If the owner is deleted, all the cats and dogs 
 associated with the owner will be deleted.

 On Sunday, 28 January 2018 10:43:54 UTC+5:30, tangoward15 wrote:
>
> Will try it now. 
>
> Quesion about the on_delete=models.CASCADE, does this mean that if I 
> delete the pet (dog or cat) it will delete the owner who owns them?
>
> On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence  
> wrote:
>
>> Your

Re: CRUD code feedback

2018-01-27 Thread tango ward
Sorry for being a drag, I tried this code:

class CreateDog(CreateView):
template_name = 'dogs_cats/create_dog.html'
model = Dog
fields = ('name', 'bday', 'owner')

def get_initial(self):
initial_data = super(CreateDog, self).get_initial()
initial_data["owner"] = [(self.request.user.id,
self.request.user.username)]
return initial_data


still I am getting the Admin user in the drop down list for owner.

On Sun, Jan 28, 2018 at 2:31 PM, Akhil Lawrence 
wrote:

>
> override get_initial and set only the logged in user
>
> class CreateDog(CreateView):
> ...
> def get_initial(self):
> initial_data = super(CreateDog, self).get_initial()
> initial_data["owner"] = [(self.request.user.id,
> self.request.user.username)]
> return initial_data
>
>
>
>
> On Sunday, 28 January 2018 11:52:31 UTC+5:30, tangoward15 wrote:
>>
>> I updated my models. py
>>
>> from django.db import models
>> from django.contrib.auth import get_user_model
>> from django.contrib.auth.models import User, PermissionsMixin
>>
>> # Create your models here.
>>
>>
>> Pet_Owner = get_user_model()
>>
>>
>> class RegisteredUser(User, PermissionsMixin):
>>
>> def __str__(self):
>> return self.username
>>
>>
>> class Dog(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(Pet_Owner, related_name='dogs',
>> on_delete=models.CASCADE)
>>
>> def __str__(self):
>> return self.name + ' - ' + str(self.owner)
>>
>>
>> class Cat(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(Pet_Owner, related_name='cats',
>> on_delete=models.CASCADE)
>>
>> def __str__(self):
>> return self.name + ' - ' + str(self.owner)
>>
>>
>> I can see all users as drop down list for owner field using Pet_Owner =
>> get_user_model() .Problem is, it shows all the Users in the project not the
>> only one who is currently logged in.
>>
>> On Sun, Jan 28, 2018 at 2:06 PM, Akhil Lawrence 
>> wrote:
>>
>>> Its the reverse. If the owner is deleted, all the cats and dogs
>>> associated with the owner will be deleted.
>>>
>>> On Sunday, 28 January 2018 10:43:54 UTC+5:30, tangoward15 wrote:

 Will try it now.

 Quesion about the on_delete=models.CASCADE, does this mean that if I
 delete the pet (dog or cat) it will delete the owner who owns them?

 On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence 
 wrote:

> Your create view do not accept owner as a input and according to your
> models, owner can be null. That's the problem. Include owner to your 
> create
> view fields as shown below. Also you may consider making owner mandatory 
> as
> mentioned in my previous response.
>
>
> class CreateDog(CreateView):
> model = Dog
> fields = ('name', 'bday', 'owner')
> template_name = 'animals/dog_create.html'
>
>
> class CreateCat(CreateView):
> model = Cat
> fields = ('name', 'bday', 'owner')
> template_name = 'animals/cat_create.html'
>
> 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...@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/340fa5fd-1475
> -4355-821c-82404b71b6bb%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/ms
>>> gid/django-users/09d7c9ca-7dab-4787-94d9-09b3a1bc682a%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 v

Re: CRUD code feedback

2018-01-27 Thread Akhil Lawrence

override get_initial and set only the logged in user

class CreateDog(CreateView):
...
def get_initial(self):
initial_data = super(CreateDog, self).get_initial()
initial_data["owner"] = [(self.request.user.id, 
self.request.user.username)]
return initial_data




On Sunday, 28 January 2018 11:52:31 UTC+5:30, tangoward15 wrote:
>
> I updated my models. py
>
> from django.db import models
> from django.contrib.auth import get_user_model
> from django.contrib.auth.models import User, PermissionsMixin
>
> # Create your models here.
>
>
> Pet_Owner = get_user_model()
>
>
> class RegisteredUser(User, PermissionsMixin):
>
> def __str__(self):
> return self.username
>
>
> class Dog(models.Model):
> name = models.CharField(max_length=40)
> bday = models.DateField()
> owner = models.ForeignKey(Pet_Owner, related_name='dogs', 
> on_delete=models.CASCADE)
>
> def __str__(self):
> return self.name + ' - ' + str(self.owner)
>
>
> class Cat(models.Model):
> name = models.CharField(max_length=40)
> bday = models.DateField()
> owner = models.ForeignKey(Pet_Owner, related_name='cats', 
> on_delete=models.CASCADE)
>
> def __str__(self):
> return self.name + ' - ' + str(self.owner)
>
>
> I can see all users as drop down list for owner field using Pet_Owner = 
> get_user_model() .Problem is, it shows all the Users in the project not the 
> only one who is currently logged in.
>
> On Sun, Jan 28, 2018 at 2:06 PM, Akhil Lawrence  > wrote:
>
>> Its the reverse. If the owner is deleted, all the cats and dogs 
>> associated with the owner will be deleted.
>>
>> On Sunday, 28 January 2018 10:43:54 UTC+5:30, tangoward15 wrote:
>>>
>>> Will try it now. 
>>>
>>> Quesion about the on_delete=models.CASCADE, does this mean that if I 
>>> delete the pet (dog or cat) it will delete the owner who owns them?
>>>
>>> On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence  
>>> wrote:
>>>
 Your create view do not accept owner as a input and according to your 
 models, owner can be null. That's the problem. Include owner to your 
 create 
 view fields as shown below. Also you may consider making owner mandatory 
 as 
 mentioned in my previous response.


 class CreateDog(CreateView):
 model = Dog
 fields = ('name', 'bday', 'owner')
 template_name = 'animals/dog_create.html'


 class CreateCat(CreateView):
 model = Cat
 fields = ('name', 'bday', 'owner')
 template_name = 'animals/cat_create.html'

 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...@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/340fa5fd-1475-4355-821c-82404b71b6bb%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/09d7c9ca-7dab-4787-94d9-09b3a1bc682a%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/d5f91e94-bd91-47d4-9a26-bfbd56283f00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread tango ward
I updated my models. py

from django.db import models
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User, PermissionsMixin

# Create your models here.


Pet_Owner = get_user_model()


class RegisteredUser(User, PermissionsMixin):

def __str__(self):
return self.username


class Dog(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(Pet_Owner, related_name='dogs',
on_delete=models.CASCADE)

def __str__(self):
return self.name + ' - ' + str(self.owner)


class Cat(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(Pet_Owner, related_name='cats',
on_delete=models.CASCADE)

def __str__(self):
return self.name + ' - ' + str(self.owner)


I can see all users as drop down list for owner field using Pet_Owner =
get_user_model() .Problem is, it shows all the Users in the project not the
only one who is currently logged in.

On Sun, Jan 28, 2018 at 2:06 PM, Akhil Lawrence 
wrote:

> Its the reverse. If the owner is deleted, all the cats and dogs associated
> with the owner will be deleted.
>
> On Sunday, 28 January 2018 10:43:54 UTC+5:30, tangoward15 wrote:
>>
>> Will try it now.
>>
>> Quesion about the on_delete=models.CASCADE, does this mean that if I
>> delete the pet (dog or cat) it will delete the owner who owns them?
>>
>> On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence 
>> wrote:
>>
>>> Your create view do not accept owner as a input and according to your
>>> models, owner can be null. That's the problem. Include owner to your create
>>> view fields as shown below. Also you may consider making owner mandatory as
>>> mentioned in my previous response.
>>>
>>>
>>> class CreateDog(CreateView):
>>> model = Dog
>>> fields = ('name', 'bday', 'owner')
>>> template_name = 'animals/dog_create.html'
>>>
>>>
>>> class CreateCat(CreateView):
>>> model = Cat
>>> fields = ('name', 'bday', 'owner')
>>> template_name = 'animals/cat_create.html'
>>>
>>> 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...@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/340fa5fd-1475-4355-821c-82404b71b6bb%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/09d7c9ca-7dab-4787-94d9-09b3a1bc682a%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/CAA6wQLJHAucw119D%2BfjO_Y4ADANe82PSjFk4vxVJdNU_ESurWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread Akhil Lawrence
There are two ways to do this. 

1. You can set the owner as the logged in user by default
2. You can provide all possible owners as options and the user can select 
the owner from a dropdown.

For case 1, you may not want to display the owner field in frontend. Here 
you can override form_valid and set the owner as logged in user.

class CreateDog(CreateView):
...
def form_valid(self, form):
form.instance.owner = self.request.user
return super(CreateDog, self).form_valid(form)

For more details:
https://docs.djangoproject.com/en/2.0/topics/class-based-views/generic-editing/#models-and-request-user
http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#form_valid


For case 2, you need to populate the list of owners by overriding the 
get_initial method.

class CreateDog(CreateView):
...
def get_initial(self):
initial_data = super(CreateDog, self).get_initial()
initial_data["owner"] = [(x.id, x.name) for x in 
Owner.objects.all()]
return initial_data

For more details:
https://docs.djangoproject.com/en/2.0/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.initial
http://ccbv.co.uk/projects/Django/1.11/django.views.generic.edit/CreateView/#get_initial

On Sunday, 28 January 2018 11:18:28 UTC+5:30, tangoward15 wrote:
>
> When I added the owner field, it doesn't have any value though the user is 
> already registered. 
>
> how do i make it mandatory in createview?
>
>
> owner = Owner.objects.create_user(username="blah", password="blah", email="
> bl...@blah.com ")
> dog = Dog(name="mydog", bday=datetime.today(), owner=owner).save()
>
>
> On Sun, Jan 28, 2018 at 1:13 PM, tango ward  > wrote:
>
>> Will try it now. 
>>
>> Quesion about the on_delete=models.CASCADE, does this mean that if I 
>> delete the pet (dog or cat) it will delete the owner who owns them?
>>
>> On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence > > wrote:
>>
>>> Your create view do not accept owner as a input and according to your 
>>> models, owner can be null. That's the problem. Include owner to your create 
>>> view fields as shown below. Also you may consider making owner mandatory as 
>>> mentioned in my previous response.
>>>
>>>
>>> class CreateDog(CreateView):
>>> model = Dog
>>> fields = ('name', 'bday', 'owner')
>>> template_name = 'animals/dog_create.html'
>>>
>>>
>>> class CreateCat(CreateView):
>>> model = Cat
>>> fields = ('name', 'bday', 'owner')
>>> template_name = 'animals/cat_create.html'
>>>
>>> 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...@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/340fa5fd-1475-4355-821c-82404b71b6bb%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/8ffa55b6-d1fe-453e-8264-5b57f84c9bb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread Akhil Lawrence
Its the reverse. If the owner is deleted, all the cats and dogs associated 
with the owner will be deleted.

On Sunday, 28 January 2018 10:43:54 UTC+5:30, tangoward15 wrote:
>
> Will try it now. 
>
> Quesion about the on_delete=models.CASCADE, does this mean that if I 
> delete the pet (dog or cat) it will delete the owner who owns them?
>
> On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence  > wrote:
>
>> Your create view do not accept owner as a input and according to your 
>> models, owner can be null. That's the problem. Include owner to your create 
>> view fields as shown below. Also you may consider making owner mandatory as 
>> mentioned in my previous response.
>>
>>
>> class CreateDog(CreateView):
>> model = Dog
>> fields = ('name', 'bday', 'owner')
>> template_name = 'animals/dog_create.html'
>>
>>
>> class CreateCat(CreateView):
>> model = Cat
>> fields = ('name', 'bday', 'owner')
>> template_name = 'animals/cat_create.html'
>>
>> 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...@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/340fa5fd-1475-4355-821c-82404b71b6bb%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/09d7c9ca-7dab-4787-94d9-09b3a1bc682a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread tango ward
When I added the owner field, it doesn't have any value though the user is
already registered.

how do i make it mandatory in createview?


owner = Owner.objects.create_user(username="blah", password="blah", email="
b...@blah.com")
dog = Dog(name="mydog", bday=datetime.today(), owner=owner).save()


On Sun, Jan 28, 2018 at 1:13 PM, tango ward  wrote:

> Will try it now.
>
> Quesion about the on_delete=models.CASCADE, does this mean that if I
> delete the pet (dog or cat) it will delete the owner who owns them?
>
> On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence 
> wrote:
>
>> Your create view do not accept owner as a input and according to your
>> models, owner can be null. That's the problem. Include owner to your create
>> view fields as shown below. Also you may consider making owner mandatory as
>> mentioned in my previous response.
>>
>>
>> class CreateDog(CreateView):
>> model = Dog
>> fields = ('name', 'bday', 'owner')
>> template_name = 'animals/dog_create.html'
>>
>>
>> class CreateCat(CreateView):
>> model = Cat
>> fields = ('name', 'bday', 'owner')
>> template_name = 'animals/cat_create.html'
>>
>> 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/ms
>> gid/django-users/340fa5fd-1475-4355-821c-82404b71b6bb%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/CAA6wQLLNJE0vO%3DGbMEy00C9RO-J3dnT-hBOxAPcVYc-Y1t6_fA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread tango ward
Will try it now.

Quesion about the on_delete=models.CASCADE, does this mean that if I delete
the pet (dog or cat) it will delete the owner who owns them?

On Sun, Jan 28, 2018 at 1:11 PM, Akhil Lawrence 
wrote:

> Your create view do not accept owner as a input and according to your
> models, owner can be null. That's the problem. Include owner to your create
> view fields as shown below. Also you may consider making owner mandatory as
> mentioned in my previous response.
>
>
> class CreateDog(CreateView):
> model = Dog
> fields = ('name', 'bday', 'owner')
> template_name = 'animals/dog_create.html'
>
>
> class CreateCat(CreateView):
> model = Cat
> fields = ('name', 'bday', 'owner')
> template_name = 'animals/cat_create.html'
>
> 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/340fa5fd-1475-4355-821c-82404b71b6bb%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/CAA6wQLKoJ9TkUo-CvhxVFKVkyeHfVS-%2Bk4HRQNPk_1OW5%2B_Oqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread Akhil Lawrence
Your create view do not accept owner as a input and according to your models, 
owner can be null. That's the problem. Include owner to your create view fields 
as shown below. Also you may consider making owner mandatory as mentioned in my 
previous response.


class CreateDog(CreateView):
model = Dog
fields = ('name', 'bday', 'owner')
template_name = 'animals/dog_create.html'


class CreateCat(CreateView):
model = Cat
fields = ('name', 'bday', 'owner')
template_name = 'animals/cat_create.html'

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/340fa5fd-1475-4355-821c-82404b71b6bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread tango ward
Hi,

Thanks for the response Akhil,

I am using the CreateView in my view.py to create ne pets


class CreateDog(CreateView):
model = Dog
fields = ('name', 'bday')
template_name = 'animals/dog_create.html'


class CreateCat(CreateView):
model = Cat
fields = ('name', 'bday')
template_name = 'animals/cat_create.html'



On Sun, Jan 28, 2018 at 11:49 AM, Akhil Lawrence 
wrote:

> Hi Jarvis,
>
> The code which you have posted only shows the model. Within your cat and
> dog models the owner can be null. Which explains why the owner is not
> associated with the pets. Can I see the code you tried to insert the
> records?
>
> ## changes needed in models
> models.ForeignKey(Owner, related_name='cats', on_delete=models.CASCADE)
> models.ForeignKey(Owner, related_name='dogs', on_delete=models.CASCADE)
>
> ## code for inserting records
> owner = Owner.objects.create_user(username="blah", password="blah",
> email="b...@blah.com")
> dog = Dog(name="mydog", bday=datetime.today(), owner=owner).save()
>
>
> Thanks.
>
>
> On Sunday, 28 January 2018 07:10:31 UTC+5:30, tangoward15 wrote:
>>
>>
>> Hi,
>>
>> I am playing around with CRUD. I want a user a create an account first
>> before he/she can add pets under his/her profile. I tried adding one pet
>> however it's seems that it is not associated to the Owner who added the pet.
>>
>> models.py
>>
>> from django.db import models
>> from django.contrib.auth.models import User, PermissionsMixin
>> from django.urls import reverse
>> # Create your models here.
>>
>>
>> class Owner(User, PermissionsMixin):
>>
>> def __str__(self):
>> return self.username
>>
>>
>> class Cat(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(Owner, related_name='cats', null=True,
>> on_delete=models.SET_NULL)
>>
>> def get_absolute_url(self):
>> return reverse('test')
>>
>> def __str__(self):
>> return self.name
>>
>>
>> class Dog(models.Model):
>> name = models.CharField(max_length=40)
>> bday = models.DateField()
>> owner = models.ForeignKey(Owner, related_name='dogs', null=True,
>> on_delete=models.SET_NULL)
>>
>> def get_absolute_url(self):
>> return reverse('test')
>>
>> def __str__(self):
>> return self.name
>>
>>
>> Any suggestions will be highly appreciated.
>>
>>
>> Regards,
>> Jarvis
>>
> --
> 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/8f31afb0-2a9d-49ef-94b4-213aef140cf2%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/CAA6wQL%2BxQMxL7QVhWs%2Bx_mYST%3D5GRStGgEtjhz6XHvu49AFuEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Customizable Invoice

2018-01-27 Thread Rakhee Menon
Hi Everyone,

I want to create a customizable invoice format wherein i can drag and drop 
the fields to any position and can save the current format and print the 
invoice .
Please can anyone help me out with it.

Thanks in Advance
Regards  ,
Rakhee

-- 
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/d85b47e9-8516-4544-8fca-67b4a2b01ebb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CRUD code feedback

2018-01-27 Thread Akhil Lawrence
Hi Jarvis,

The code which you have posted only shows the model. Within your cat and 
dog models the owner can be null. Which explains why the owner is not 
associated with the pets. Can I see the code you tried to insert the 
records?

## changes needed in models
models.ForeignKey(Owner, related_name='cats', on_delete=models.CASCADE)
models.ForeignKey(Owner, related_name='dogs', on_delete=models.CASCADE)

## code for inserting records
owner = Owner.objects.create_user(username="blah", password="blah", 
email="b...@blah.com")
dog = Dog(name="mydog", bday=datetime.today(), owner=owner).save()


Thanks.

On Sunday, 28 January 2018 07:10:31 UTC+5:30, tangoward15 wrote:
>
>
> Hi,
>
> I am playing around with CRUD. I want a user a create an account first 
> before he/she can add pets under his/her profile. I tried adding one pet 
> however it's seems that it is not associated to the Owner who added the pet.
>
> models.py
>
> from django.db import models
> from django.contrib.auth.models import User, PermissionsMixin
> from django.urls import reverse
> # Create your models here.
>
>
> class Owner(User, PermissionsMixin):
>
> def __str__(self):
> return self.username
>
>
> class Cat(models.Model):
> name = models.CharField(max_length=40)
> bday = models.DateField()
> owner = models.ForeignKey(Owner, related_name='cats', null=True, 
> on_delete=models.SET_NULL)
>
> def get_absolute_url(self):
> return reverse('test')
>
> def __str__(self):
> return self.name
>
>
> class Dog(models.Model):
> name = models.CharField(max_length=40)
> bday = models.DateField()
> owner = models.ForeignKey(Owner, related_name='dogs', null=True, 
> on_delete=models.SET_NULL)
>
> def get_absolute_url(self):
> return reverse('test')
>
> def __str__(self):
> return self.name
>
>
> Any suggestions will be highly appreciated.
>
>
> Regards,
> Jarvis
>

-- 
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/8f31afb0-2a9d-49ef-94b4-213aef140cf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


CRUD code feedback

2018-01-27 Thread tango ward
Hi,

I am playing around with CRUD. I want a user a create an account first
before he/she can add pets under his/her profile. I tried adding one pet
however it's seems that it is not associated to the Owner who added the pet.

models.py

from django.db import models
from django.contrib.auth.models import User, PermissionsMixin
from django.urls import reverse
# Create your models here.


class Owner(User, PermissionsMixin):

def __str__(self):
return self.username


class Cat(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(Owner, related_name='cats', null=True,
on_delete=models.SET_NULL)

def get_absolute_url(self):
return reverse('test')

def __str__(self):
return self.name


class Dog(models.Model):
name = models.CharField(max_length=40)
bday = models.DateField()
owner = models.ForeignKey(Owner, related_name='dogs', null=True,
on_delete=models.SET_NULL)

def get_absolute_url(self):
return reverse('test')

def __str__(self):
return self.name


Any suggestions will be highly appreciated.


Regards,
Jarvis

-- 
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/CAA6wQL%2BphX%3Dy8RnuHzfG1u7Z68%3Difpy6-3HFgVrQGitSCqBniA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


javascript transpilers

2018-01-27 Thread Mike Dewhirst
I have avoided javascript like the plague. However it seems I have to 
bite the bullet. Interestingly, there are now a number of Python -> 
Javascript transpilers.


http://stromberg.dnsalias.org/~strombrg/pybrowser/python-browser.html

Where would be a good place to start a discussion on the topic?

I am self-employed  with multiple demands on my time so I cannot afford 
to allocate sufficient time to learn it let alone undertake formal 
Javascript training. My hope is to pick it up by osmosis and wonder if a 
transpiler would help.


Thanks for any pointers

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/fa0e9f0b-fece-344d-74f2-5b9470b40657%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Get request, has PK, how do I access the PK data with in the model

2018-01-27 Thread Matemática A3K
https://docs.djangoproject.com/en/2.0/intro/tutorial01/

On Sat, Jan 27, 2018 at 8:19 AM, Travis Pickle 
wrote:

> Andy,
>
> Do you have a link for this? 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/7bc86b9f-57d4-4a57-aa2e-bf6f1a163458%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/CA%2BFDnhL3K4gYr0ohD-eANW2jtzPN%2BUcBROqG2U7--XNOsBQPNA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Native JIT compiler for Django?

2018-01-27 Thread Etienne Robillard

Hi,

I would like to know if it's possible to compile Django code with a JIT 
compiler to a C file using LLVM?


What do you think?

Etienne


Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/

--
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/ec8bf736-c316-8e9a-01ec-16383c78e746%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic update template

2018-01-27 Thread Ruchit Bhatt
Ok.Thank you so much for reply.

-- 
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/fa6755ae-21fb-4833-a8b6-536c0002d56c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

2018-01-27 Thread Andréas Kühne
If you are not running with the following statement in settings.py:

DEBUG = True

AND you have to run the server with "python manage.py runserver", if you
are running it in any other way, you have to setup ALLOWED_HOSTS.

You could also (but definitely not recommended) set ALLOWED_HOSTS = ['*']

That would remove the checks for hosts in a production environment.

Regards,

Andréas

2018-01-27 15:04 GMT+01:00 bootcamprag :

> Hello
>
> I am using django 2.0 and I cannot resolve the the error in the subject
> line when I run the local server. I am in the development phase. Not
> production. Please assist. Thanks.
>
> r,
>
> Demayne
>
> --
> 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/bde54c16-961b-4817-bc22-74ecabffd341%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/CAK4qSCfNGnhD3cpFSWySxjwM%3D85%2BQgiyQN57fpzErKR_zLhO%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

2018-01-27 Thread Jason
uhm, implement the setting for your enviroment?

https://docs.djangoproject.com/en/2.0/ref/settings/#allowed-hosts

On Saturday, January 27, 2018 at 9:04:17 AM UTC-5, bootcamprag wrote:
>
> Hello 
>
> I am using django 2.0 and I cannot resolve the the error in the subject 
> line when I run the local server. I am in the development phase. Not 
> production. Please assist. Thanks.
>
> r,
>
> Demayne
>

-- 
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/c27503df-0ffe-489c-9fec-681e73bd8f0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic update template

2018-01-27 Thread Jason
Any of those options work for the frontend.  I wouldn't worry so much about 
the reading the code for the following reasons:

   1. You're most likely using a build step for production deployment which 
   concatenates all the files into one and minifies it after, with renaming of 
   functions, classes and variables.  So its pretty tough to pick through 
   where does what
   2. You should leverage Django Rest Framework's permission, 
   authentication, throttling and other features to create tokens that would 
   be included in the client request to validate that User X  is authorized 
   for this API endpoint and implement resource throttling to X requests over 
   Y period of time.
   3. You should be using https to create a secure request-response 
   connection that would prevent any man-in-the-middle spoofing where a bad 
   actor can position itself between client and server.

-- 
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/7a0ce61e-05d2-4e5e-a11b-ecb33c4cf911%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

2018-01-27 Thread bootcamprag
Hello 

I am using django 2.0 and I cannot resolve the the error in the subject 
line when I run the local server. I am in the development phase. Not 
production. Please assist. Thanks.

r,

Demayne

-- 
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/bde54c16-961b-4817-bc22-74ecabffd341%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic update template

2018-01-27 Thread Ruchit Bhatt
Ok,so you are suggesting front-end framework to make life easier. Do you have 
any personal choice over angularjs / React / Vue ? One more thing, how security 
will work in this case because javascript runs on client side & anybody can 
read how js code comunicating with backend ?

-- 
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/3af04d03-9142-4cf7-85a8-c9521dabe41e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic update template

2018-01-27 Thread Jani Tiainen
Hi.

Unfortunately doing ajax calls to partially update page is required.

It is possible to write all the javascript needed by hand but using
frameworks usually makes things easier.

27.1.2018 13.32 "Ruchit Bhatt"  kirjoitti:

> Hi folks,
> Currently i am using Django at basic/intermediate level. And in my web
> template, single page contains more than one *Forms*, many *chart.js*
> widgets for to plot graph, plus 2-3 small widget for task management.
> Now i want to make my site more dynamic (i.e update UI without reloading
> whole page).
>
> For this, some articles suggest AJAX, some are AngularJs or React or Vue
> supporter.
> My question is can't we do this by using only Django (i.e without using
> frontend framework)?
>
>
> --
> 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/03910d6a-5305-47a2-8bf3-a08535e614b6%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/CAHn91oddi4nY8iXCNt-g8V9d-tF5UXnzJO_k0BhQ0iFrqhq9DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Dynamic update template

2018-01-27 Thread Ruchit Bhatt
Hi folks,
Currently i am using Django at basic/intermediate level. And in my web 
template, single page contains more than one *Forms*, many *chart.js* 
widgets for to plot graph, plus 2-3 small widget for task management.
Now i want to make my site more dynamic (i.e update UI without reloading 
whole page).

For this, some articles suggest AJAX, some are AngularJs or React or Vue 
supporter.
My question is can't we do this by using only Django (i.e without using 
frontend framework)?


-- 
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/03910d6a-5305-47a2-8bf3-a08535e614b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Get request, has PK, how do I access the PK data with in the model

2018-01-27 Thread Travis Pickle
Andy,

Do you have a link for this? 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/7bc86b9f-57d4-4a57-aa2e-bf6f1a163458%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploying SSL for my Django 2.0.1 server with Apache on Ubuntu 16.04 (droplet)

2018-01-27 Thread Antonis Christofides
>
> But the following is still saying, “Forbidden”:
>
>
> https://www.angeles4four.info/static/admin/
>
This is normal. The reason is not the filesystem permissions, but that Apache is
configured to not list files inside that directory (to change that you'd need to
use "Options Indexes" somewhere, but you don't want to change that). You can
still access any file in that directory, but it will not tell you which files
are available. This is the correct thing to do.

> ...
>
> drwxrwxr-x  5 tranq www-data  4096 Jan 25 23:12 cel2fah
>
>
> Does this look right to all of you?
>
It's OK, though it could be better. Apache only needs to read that directory,
not write it. Apache is user www-data and group www-data, and this directory is
writeable by group www-data, that is, writeable by Apache. So better permissions
for that would be drwxr-xr-x (which you can achieve with "chmod 755 cel2fah" or
"chmod g-w cel2fah").

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-01-27 07:20, drone4four wrote:
>
> The username on my droplet is ‘tranq’ but there is a line in both my vhost
> config files which reads:
>
>
> 
>
>
> So I swapped out ‘user’ for ‘tranq’. That line now reads:
>
>
> 
>
>
> Now some of my static files are accessible.  For example you can see here:
>
>
> https://www.angeles4four.info/static/admin/css/responsive.css
>
> https://www.angeles4four.info/static/admin/css/login.css
>
>
> But the following is still saying, “Forbidden”:
>
>
> https://www.angeles4four.info/static/admin/
>
>
> This may be pointing to an issue I noticed with how my user and group
> permissions are set up for Django.  The sqlite.db file was grouped in with
> ‘tranq’. According to the guide I’ve been using, it should be: ‘www-data’.
>  I’m not sure how I overlooked this mistake because I very clearly remember
> doing it properly.  I think I’m conflating this with one of my multiple recent
> previous attempts following this guide. Anyways, here is what my group
> permissions look like now from within my project directory:
>
>
> $ ls -la
>
> total 68
>
> drwxrwxr-x  5 tranq www-data  4096 Jan 25 23:12 .
>
> drwxr-xr-x 18 tranq tranq 4096 Jan 26 21:57 ..
>
> drwxrwxr-x  3 tranq tranq 4096 Jan 25 23:13 cel2fah
>
> -rw-rw-r--  1 tranq www-data 38912 Jan 25 23:11 db.sqlite3
>
> -rwxrwxr-x  1 tranq tranq  539 Jan 25 23:05 manage.py
>
> drwxrwxr-x  3 tranq tranq 4096 Jan 25 23:12 static
>
> drwxrwxr-x  5 tranq tranq 4096 Jan 25 23:04 venv
>
>
> Notice sqlite.db above? It now says ‘www-data’.  This is how it should be, 
> right?
>
>
> The parent directory (home user folder) shows these permissions for my 
> project:
>
>
> ...
>
> drwxrwxr-x  5 tranq www-data  4096 Jan 25 23:12 cel2fah
>
>
> Does this look right to all of you?
>
>
> The steps I took to arrange the permissions as such were from the bottom of
> the mod_wsgi guide on DigitalOcean
> which
> I referred to initially.
> Thanks for your attention.
> On Friday, January 26, 2018 at 1:21:07 AM UTC-5, drone4four wrote:
>
> You’re right, @Antonis, that I don’t want my Django source code exposed.
> No sysadmin would.  I have since moved my Django project folder to my home
> user’s directory. However (out of curiosity), if I continued to house
> Django in my public_html folder (which I am not any more, but say if i
> did) I would think that my .htaccess config file would prevent
> unauthorized access to my Django source.  Am I right?
>
>
> I didn’t realize that Django was suppose to be run using wsgi.  I was just
> foolishly running the server with ``$ python manage.py runserver
> 0.0.0.0:8000`` like when I was testing locally when I was coding my app.
> The keyword here is mod_wsgi.  So I found this guide
> 
> .
> I followed along but the issue I now have is that Apache serves my
> public_html folder (just some light  HTML, CSS and Js).  Serving these
> contents take priority over Django.  I’m OK with this. I would prefer to
> keep my public_html folder accessible as it is, but how do I arrange for
> wsgi to serve Django from a subdirectory, say:
> www.angeles4four.info/cel2fah or
> something like that?
>
>
> @Mulianto:
>
> An example of a static file would be a style sheet, like:
> ~/cel2fah/static/admin/css/responsive.css
>
> How would trying to access this CSS file help?
>
> I tried:
>
> http://www.angeles4four.info:8000/cel2fah/static/admin/css/responsive.css
> 
>