Re: Nested Model Issue

2019-08-10 Thread mohamed habib
You can use a signal to ensure that a profile is created for each user.
Make sure all the fields in your Profile model are nullable:

```
class Profile(models.Model):

GENDER_CHOICES = (
  ('male', 'Male'),
  ('female', 'Female')
)
user = models.ForeignKey(User,on_delete=models.CASCADE,related_name
= 'usermodel')
permanent_address_city =
models.ForeignKey(Address,on_delete=models.CASCADE,related_name =
'permanent_address_city', null=True, blank=True)
phone_number = models.PositiveIntegerField(, null=True, blank=True)
gender = models.CharField(max_length = 5,choices = GENDER_CHOICES,
null=True, blank=True)
profile_pic = models.ImageField(upload_to='profile_pic',default =
'default.jpg', null=True, blank=True)
created_at = models.DateField(auto_now_add = True, null=True, blank=True)
updated_at = models.DateField(auto_now = True, null=True, blank=True)

```

use signal within your models.py to create a blank profile every time
a User object is created:


```

from django.db.models.signals import post_save

from django.dispatch import receiver
@receiver(post_save, sender=settings.AUTH_USER_MODEL)def
create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)

```

Now you can create an Update profile view to update the user based on
the fields he has placed in the instance using your serialiser. You
can have a separate view to create an address object. The User Profile
update view can take the ID of an address and attach that address to
the user.



On Sat, Aug 10, 2019 at 9:55 PM Soumen Khatua 
wrote:

> Hi Folks,
> My requirement is whenever i create a user in post method that user can
> pass username and password, Address models contain some field and Profile
> models contains some field. If he is authenticated users and want to create
> one prifile he need to pass Address model contains some field and Profile
> models contain some fields information. I'm stuckung in this problem from
> last four days. Please help me with complete code actually I'm not that
> much good in Django rest framework. please help me guys.
>
> These are my models for your reference:
>
>
> models.py:
> ---
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *from django.db import modelsfrom django.contrib.auth.models import User#
> Create your models here.class Address(models.Model):street_no =
> models.CharField(max_length = 65)city = models.CharField(max_length =
> 65)state = models.CharField(max_length = 65)pincode =
> models.CharField(max_length = 65)country = models.CharField(max_length
> = 65)created_at = models.DateField(auto_now_add = True)updated_at =
> models.DateField(auto_now = True)def __str__(self):return
> self.cityclass Profile(models.Model):GENDER_CHOICES = (  ('male',
> 'Male'),  ('female', 'Female'))user =
> models.ForeignKey(User,on_delete=models.CASCADE,related_name =
> 'usermodel')permanent_address_city =
> models.ForeignKey(Address,on_delete=models.CASCADE,related_name =
> 'permanent_address_city')phone_number = models.PositiveIntegerField()
>   gender = models.CharField(max_length = 5,choices = GENDER_CHOICES)
> profile_pic = models.ImageField(upload_to='profile_pic',default =
> 'default.jpg')created_at = models.DateField(auto_now_add = True)
> updated_at = models.DateField(auto_now = True)*
>
>
> *Thank you in advance*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6WZCT_fB-bgjWmLTiPDG81V5Vg-BPqeeps_QivtpddrkaQ%40mail.gmail.com
> 
> .
>


-- 
Best regards,
*Mohammed M. Habib, PhD*

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BpnY8ZpccqyPTpk8ckkqV2QiF%2BLBpGDeNA3hag0F%2Bx6wZq2Dw%40mail.gmail.com.


Re: Tutorial Problems...

2019-08-10 Thread aman kumar
 hello...
While using field type null ...
what is difference between "Empty string" and Null=True i.e null 
..value for "no data"  in string based field...?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/83c3f78b-5a57-4638-a3bb-dae1c2fd1969%40googlegroups.com.


Nested Model Issue

2019-08-10 Thread Soumen Khatua
Hi Folks,
My requirement is whenever i create a user in post method that user can
pass username and password, Address models contain some field and Profile
models contains some field. If he is authenticated users and want to create
one prifile he need to pass Address model contains some field and Profile
models contain some fields information. I'm stuckung in this problem from
last four days. Please help me with complete code actually I'm not that
much good in Django rest framework. please help me guys.

These are my models for your reference:


models.py:
---




























*from django.db import modelsfrom django.contrib.auth.models import User#
Create your models here.class Address(models.Model):street_no =
models.CharField(max_length = 65)city = models.CharField(max_length =
65)state = models.CharField(max_length = 65)pincode =
models.CharField(max_length = 65)country = models.CharField(max_length
= 65)created_at = models.DateField(auto_now_add = True)updated_at =
models.DateField(auto_now = True)def __str__(self):return
self.cityclass Profile(models.Model):GENDER_CHOICES = (  ('male',
'Male'),  ('female', 'Female'))user =
models.ForeignKey(User,on_delete=models.CASCADE,related_name =
'usermodel')permanent_address_city =
models.ForeignKey(Address,on_delete=models.CASCADE,related_name =
'permanent_address_city')phone_number = models.PositiveIntegerField()
  gender = models.CharField(max_length = 5,choices = GENDER_CHOICES)
profile_pic = models.ImageField(upload_to='profile_pic',default =
'default.jpg')created_at = models.DateField(auto_now_add = True)
updated_at = models.DateField(auto_now = True)*


*Thank you in advance*

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


Re: LANGUAGE_CODE

2019-08-10 Thread DANIEL URBANO DE LA RUA
It may be not getting yor locale from your folders

On Sun, 28 Jul 2019, 20:09 Yves de Champlain  HI
>
> Django translation works very well for me, except that when I try to
> change LANGUAGE_CODE in settings.py, my site remains in French. I need to
> change my OS system settings to see the English version.
>
> I have two languages, English as default and a French Translation.
>
> LANGUAGES = (
> ('en', _('English')),
> ('fr', _('French')),
> )
>
> LANGUAGE_CODE = 'en'
>
> Thanks for your insights !
>
> yves
>
>
> --
> You received this message because you are subscribed to the Google 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3a301603-3237-4674-9d8d-2f6362d3154e%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO_yRT3KrYF5V7LnogT99KNpVngeX74A_CtfaLCdk-bLZrgFMA%40mail.gmail.com.


Re: LANGUAGE_CODE

2019-08-10 Thread DANIEL URBANO DE LA RUA
Prefix_default_language in urls file inside i18n_patterns

On Sun, 28 Jul 2019, 20:09 Yves de Champlain  HI
>
> Django translation works very well for me, except that when I try to
> change LANGUAGE_CODE in settings.py, my site remains in French. I need to
> change my OS system settings to see the English version.
>
> I have two languages, English as default and a French Translation.
>
> LANGUAGES = (
> ('en', _('English')),
> ('fr', _('French')),
> )
>
> LANGUAGE_CODE = 'en'
>
> Thanks for your insights !
>
> yves
>
>
> --
> You received this message because you are subscribed to the Google 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3a301603-3237-4674-9d8d-2f6362d3154e%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO_yRT3A1-b2bbn-cJxXr6NPH5aSgVTLp_%3DaBuTneG-re_mGKg%40mail.gmail.com.


Re: LANGUAGE_CODE

2019-08-10 Thread Yves de Champlain
Hi

I looked for the cookie, but did not find it. 

How do you find them when running django server on localhost:8000 ?

yves


Le dimanche 28 juillet 2019 22:57:42 UTC-4, Aldian Fazrihady a écrit :
>
> Hi Yves, please clear cookies and refresh your django app page afterwards.
>
> It is possible to not use cookies at all regarding i18n if you use 
> language code as part of URL. I always prefer using URL for i18n. 
>
> On Mon, Jul 29, 2019 at 1:08 AM Yves de Champlain  > wrote:
>
>> HI
>>
>> Django translation works very well for me, except that when I try to 
>> change LANGUAGE_CODE in settings.py, my site remains in French. I need to 
>> change my OS system settings to see the English version.
>>
>> I have two languages, English as default and a French Translation.
>>
>> LANGUAGES = (
>> ('en', _('English')),
>> ('fr', _('French')),
>> )
>>
>> LANGUAGE_CODE = 'en'
>>
>> Thanks for your insights !
>>
>> yves
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/3a301603-3237-4674-9d8d-2f6362d3154e%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> Regards,
>
> Aldian Fazrihady
> http://aldianfazrihady.com
>

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ed9029c1-3fb6-463f-a580-d8763ef8efcc%40googlegroups.com.


Re: Django models and json integration

2019-08-10 Thread Suraj Thapa FC
Can  you pls elaborate or have any working code

On Sat, 10 Aug, 2019, 9:40 PM Andrew C.,  wrote:

> Two options:
>
> 1) Save the JSON files and link it with a FileField
>
> 2) Use PostgreSQL’s Django-specific JSONField.
>
> On Sat, Aug 10, 2019 at 9:46 AM Suraj Thapa FC 
> wrote:
>
>> How can I linked a JSON file with my db... Json files contains the key
>> value pair of the user data..
>> If the id in the db and the id in the json files matches i can fetch and
>> read 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPjsHcFbqtWJmDXrbafemf8TQkX9gROW-TxOvirvjsFut%3D5A1w%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJVmkNkTkjYFOvwPO%3DRrdtephow%2BH4rJNk0KQNriWmO%2Bm3hEmw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcECRvr3sPTPt06CZwcVpWWKTbJ%3DYHorvco49M2_B%2BNwJw%40mail.gmail.com.


Re:

2019-08-10 Thread Andrew C.
I suppose in a view, you can write something along these lines:

import json
from os import path
from django.conf import settings

def index(request):
if request.method == ‘POST’:
 form = YourForm(request.POST)
 if form.is_valid():
 field1 = form.cleaned_data.get(‘field1_from_form’)
 # write your JSON here
 # Follow this tutorial to write your json:
https://stackabuse.com/reading-and-writing-json-to-a-file-in-python/
 # Instead of dumping your file into a txt like they did in the
first example, do this:
 with open(path.join(settings.MEDIA_ROOT, “ajsonfile.json”),
“w+”) as outfile:
   json.dump(data, outfile)
  return redirect(request.get_absolute_uri())
elif request.method == “GET”:
form = YourForm()
return render(request, “index.html”, {‘form’: form}


I forgot the import statement for the redirect

On Sat, Aug 10, 2019 at 6:28 AM Suraj Thapa FC 
wrote:

> How do I write my front-end form response in..  .json file
>
> --
> You received this message because you are subscribed to the Google 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPjsHcG4%3D%3D%2BRWSeDocSiF9dGaHdt4LFi%2B-AB11Q43vOhZnY1Zg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJVmkN%3Dep5tSFa01XjfvyZdhhzVSXekcpkC1Wx1U-xR2cjP9ww%40mail.gmail.com.


Re: django.db.utils.OperationalError: (2002, 'Can\'t connect to local MySQL server through socket \'/cloudsql/instance:us-central1:project_name\' (2 "No such file or directory")')

2019-08-10 Thread Budi Hermansyah
please search for how to access your sql on gcp with ssh and with IP
addr... then
repace the following setting using that IP...
from:
'HOST': '/cloudsql/instance:us-central1:project',
to
'HOST': 'xx.xx.xx.xx',


On Sat, Aug 10, 2019 at 6:38 AM Solomon Mbak  wrote:

> Hi.
>
> For two days I have been stuck on deploying my Django app on Google App
> Engine. I cloned the project from my Github account. I have installed the
> requirements also.
>
> The database in-use is a mysql database
>
> I get an error that says "django.db.utils.OperationalError: (2002, 'Can\'t
> connect to local MySQL server through socket
> \'/cloudsql/instance:us-central1:project_name\' (2 "No such file or
> directory")')".
>
> I have tried all I can and haven't really found any solutions online.
> My database connection looks like this:
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.mysql',
> 'HOST': '/cloudsql/instance:us-central1:project',
> 'USER': 'root',
> 'PASSWORD': 'password',
> 'NAME': 'db_name',
> }
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2e58e307-8490-478f-a8cf-4cf640fde5bc%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHGmjWXvh5-TZCn4%3D6A-BzehFDM8ZM3CssaTS5%3D6kXqX9xipPg%40mail.gmail.com.


Re: How to build users tagging system in my comment textarea.

2019-08-10 Thread Andrew C.
You would probably need AJAX calls. I think there’s a package called
Django-autocompletelite which can help you with this. So, in your HTML, you
can use use AJAX to see when a user types the @ character with a single
letter and then show a box with some usernames with that.

On Sat, Aug 10, 2019 at 3:31 AM Ashutosh Kumar  wrote:

> Hi Guys,
>
> I need help in adding user tagging feature in comment textarea, like how
> to get the users list pops out on the keypress "@".
>
> --
> You received this message because you are subscribed to the Google 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAcNNf%2BjK%3DK9EopJ_O_Yjf6RXUMzZAWJfN7RJTeBYYpEQ4cVkQ%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJVmkNnH18feOURis6Lq6ohLc0_c%2BgNw5gVD0qzoRWGAWC0QiA%40mail.gmail.com.


Re: Django models and json integration

2019-08-10 Thread Andrew C.
Two options:

1) Save the JSON files and link it with a FileField

2) Use PostgreSQL’s Django-specific JSONField.

On Sat, Aug 10, 2019 at 9:46 AM Suraj Thapa FC 
wrote:

> How can I linked a JSON file with my db... Json files contains the key
> value pair of the user data..
> If the id in the db and the id in the json files matches i can fetch and
> read 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPjsHcFbqtWJmDXrbafemf8TQkX9gROW-TxOvirvjsFut%3D5A1w%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJVmkNkTkjYFOvwPO%3DRrdtephow%2BH4rJNk0KQNriWmO%2Bm3hEmw%40mail.gmail.com.


Django models and json integration

2019-08-10 Thread Suraj Thapa FC
How can I linked a JSON file with my db... Json files contains the key
value pair of the user data..
If the id in the db and the id in the json files matches i can fetch and
read 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcFbqtWJmDXrbafemf8TQkX9gROW-TxOvirvjsFut%3D5A1w%40mail.gmail.com.


[no subject]

2019-08-10 Thread Suraj Thapa FC
How do I write my front-end form response in..  .json file

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcG4%3D%3D%2BRWSeDocSiF9dGaHdt4LFi%2B-AB11Q43vOhZnY1Zg%40mail.gmail.com.


How to build users tagging system in my comment textarea.

2019-08-10 Thread Ashutosh Kumar
Hi Guys,

I need help in adding user tagging feature in comment textarea, like how to
get the users list pops out on the keypress "@".

-- 
You received this message because you are subscribed to the Google 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAcNNf%2BjK%3DK9EopJ_O_Yjf6RXUMzZAWJfN7RJTeBYYpEQ4cVkQ%40mail.gmail.com.