Re: Django rest framework Best way to link and display value.

2018-01-04 Thread cherngyorng
So foreign key is fine. Thank you. I thought that maybe theres a better way 
than using foreign key.

On Friday, January 5, 2018 at 4:38:58 PM UTC+9, Dylan Reinhold wrote:
>
> | But i have a feeling this is a very troublesome way to do it.
>
> Why do you have this feeling? Foreign key to another table sounds fine.
> If you don't think that list will change much you could do it as a choice. 
> https://docs.djangoproject.com/en/2.0/ref/models/fields/#choices
>
>
> Dylan
>
> On Thu, Jan 4, 2018 at 11:23 PM, > wrote:
>
>> I have a table called family, you can see the models.py below.
>>
>> My partner told me that he wanted the relationship to change to this kind
>> 1,Father
>> 2,Mother
>> 3,Husband
>> 4,Wife
>> 5,Son
>> 6,Daughter
>> 7,Aunt
>> 8,Uncle
>> 9,Nephew
>> 10,Niece
>> 11,Others
>>
>> This is where he will sent me the id (eg:5) and i will save that 5 into 
>> relationship field and display Son
>>
>> My way of thinking is creating a new table call relationship and hardcode 
>> each relationship 1 by 1 (all 11 of it) 
>> Then change the relationship field in Family into this : relationship = 
>> models.ForeignKey(Relationship)
>> But i have a feeling this is a very troublesome way to do it.
>>
>> Can anyone help me on what way it will be easier ?
>>
>> This is the model:
>>
>> class Family(models.Model):
>> userId = models.ForeignKey(MyUser, related_name='user_family')
>> relationship = models.CharField(max_length=100)
>> first_name = models.CharField(max_length=50)
>> last_name = models.CharField(max_length=50)
>> gender = models.CharField(max_length=6, blank=True, null=True)
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@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/275c600e-1e9a-4529-8ee1-3c7b4e2d8b60%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/77750c00-90c4-4580-8160-7807f94ba6b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django rest framework Best way to link and display value.

2018-01-04 Thread Dylan Reinhold
| But i have a feeling this is a very troublesome way to do it.

Why do you have this feeling? Foreign key to another table sounds fine.
If you don't think that list will change much you could do it as a choice.
https://docs.djangoproject.com/en/2.0/ref/models/fields/#choices


Dylan

On Thu, Jan 4, 2018 at 11:23 PM,  wrote:

> I have a table called family, you can see the models.py below.
>
> My partner told me that he wanted the relationship to change to this kind
> 1,Father
> 2,Mother
> 3,Husband
> 4,Wife
> 5,Son
> 6,Daughter
> 7,Aunt
> 8,Uncle
> 9,Nephew
> 10,Niece
> 11,Others
>
> This is where he will sent me the id (eg:5) and i will save that 5 into
> relationship field and display Son
>
> My way of thinking is creating a new table call relationship and hardcode
> each relationship 1 by 1 (all 11 of it)
> Then change the relationship field in Family into this : relationship =
> models.ForeignKey(Relationship)
> But i have a feeling this is a very troublesome way to do it.
>
> Can anyone help me on what way it will be easier ?
>
> This is the model:
>
> class Family(models.Model):
> userId = models.ForeignKey(MyUser, related_name='user_family')
> relationship = models.CharField(max_length=100)
> first_name = models.CharField(max_length=50)
> last_name = models.CharField(max_length=50)
> gender = models.CharField(max_length=6, blank=True, null=True)
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/275c600e-1e9a-4529-8ee1-3c7b4e2d8b60%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/CAHtg44DbL27LrvbjEfa%3DbSt0dZJkxW0Rda8DPd3o_FRSm2v23Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django rest framework import data from one table to another

2018-01-04 Thread cherngyorng
This is my stackoverflow link which may be able to make it look more easier 
to 
understand: 
https://stackoverflow.com/questions/48109034/django-rest-framework-import-data-from-one-table-to-another

On Friday, January 5, 2018 at 3:47:23 PM UTC+9, chern...@gmail.com wrote:
>
> I am doing a django rest framework API for ios application. And currently, 
> i am doing a function between user and family.
> Let me explain my logic between these two. 
>
> User= current user (an account that can be use to login)
> Family = current user's family member eg:father mother (it is not an 
> account, cannot be use to sign in)
>
> What i am thinking right now is that if the current user's family wanted 
> to create an account, is it possible to import the data from family table 
> to user table for that family member to register ?
>
> Example scenario : 
> user table : userId, username, password, email, phone_number, 
> identification_num, first_name, last_name
> family table :Id, userId(foreign key to user table, cannot be null) , 
> familyId(can be null, reason is to allow user to add family member that did 
> not register an account), phone_number, identification_num, first_name, 
> last_name, relationship
>
> Is it possible for user to sent invitation link to that family member, and 
> it will import the data to the family member to register an account
> - family member click on invite link
> - redirect to register page with the detail from family table.
> - If register success, insert the userId of that family member into 
> familyId of family table.
> - that family member account's family table will also update to have a 
> family data with the current user.
>
> Did i explain it clearly ? Sorry if it is not, you can tell me if it is 
> not clear enough so i can try to make it clearer.
> Is this kind of design good ? It seems like it has alot of flaw. 
> Is it possible to import all that information into that invite register 
> page ?
>
>

-- 
You received this message because you are subscribed to the Google 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/7704327c-90b0-462e-a771-b393895ecf4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django rest framework import data from one table to another

2018-01-04 Thread cherngyorng
This is my stackoverflow link which may be able to make it look more easier 
to understand

On Friday, January 5, 2018 at 3:47:23 PM UTC+9, chern...@gmail.com wrote:
>
> I am doing a django rest framework API for ios application. And currently, 
> i am doing a function between user and family.
> Let me explain my logic between these two. 
>
> User= current user (an account that can be use to login)
> Family = current user's family member eg:father mother (it is not an 
> account, cannot be use to sign in)
>
> What i am thinking right now is that if the current user's family wanted 
> to create an account, is it possible to import the data from family table 
> to user table for that family member to register ?
>
> Example scenario : 
> user table : userId, username, password, email, phone_number, 
> identification_num, first_name, last_name
> family table :Id, userId(foreign key to user table, cannot be null) , 
> familyId(can be null, reason is to allow user to add family member that did 
> not register an account), phone_number, identification_num, first_name, 
> last_name, relationship
>
> Is it possible for user to sent invitation link to that family member, and 
> it will import the data to the family member to register an account
> - family member click on invite link
> - redirect to register page with the detail from family table.
> - If register success, insert the userId of that family member into 
> familyId of family table.
> - that family member account's family table will also update to have a 
> family data with the current user.
>
> Did i explain it clearly ? Sorry if it is not, you can tell me if it is 
> not clear enough so i can try to make it clearer.
> Is this kind of design good ? It seems like it has alot of flaw. 
> Is it possible to import all that information into that invite register 
> page ?
>
>

-- 
You received this message because you are subscribed to the Google 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/3e76e56b-41ed-441d-a884-d7060af69f1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django rest framework viewset and its url

2018-01-04 Thread cherngyorng

>
> Ah, i decide to instead of using 2 viewset for a single model, i use 1 
> viewset and 1 APIView for it.

 

> Therefore i deleted both post in here and in stackoverflow. Sorry for the 
> trouble. 






On Friday, January 5, 2018 at 1:56:44 PM UTC+9, Dylan Reinhold wrote:
>
> That link is not valid, and without seeing your views no one will be able 
> to help.
>
> Dylan
>
> On Thu, Jan 4, 2018 at 7:18 PM, > wrote:
>
>> For a better and more detailed question i ask, refer to here : 
>> https://stackoverflow.com/questions/48106733/django-rest-framework-viewset-and-url-mixup
>>
>> In my project, i have 2 model. family and schedule
>>
>> As i wanted to have 1 api to get all while the other is to get current 
>> user only therefore i create 2 viewset for each serializer.
>> I also specify different url based on the different viewset i created.
>>
>> eg: router = routers.DefaultRouter()
>>
>> router.register(r'Family', views.FamilyViewSet)
>> router.register(r'Schedule2', views.ScheduleViewSet2)
>> router.register(r'CFamily', views.FamilyViewSet2)
>> router.register(r'Schedule', views.ScheduleViewSet)
>>
>> However, only the schedule works properly while family uses FamilyViewSet2 
>> for both in the API. 
>>
>> I'm confuse about this problem, please help
>>
>> -- 
>> You received this message because you are subscribed 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/9388e16f-fae4-48e2-b860-1b1cb5d0b502%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/a02faf0d-1a3e-46e7-a224-f9b190a83722%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django rest framework Best way to link and display value.

2018-01-04 Thread cherngyorng
I have a table called family, you can see the models.py below.

My partner told me that he wanted the relationship to change to this kind
1,Father
2,Mother
3,Husband
4,Wife
5,Son
6,Daughter
7,Aunt
8,Uncle
9,Nephew
10,Niece
11,Others

This is where he will sent me the id (eg:5) and i will save that 5 into 
relationship field and display Son

My way of thinking is creating a new table call relationship and hardcode 
each relationship 1 by 1 (all 11 of it) 
Then change the relationship field in Family into this : relationship = 
models.ForeignKey(Relationship)
But i have a feeling this is a very troublesome way to do it.

Can anyone help me on what way it will be easier ?

This is the model:

class Family(models.Model):
userId = models.ForeignKey(MyUser, related_name='user_family')
relationship = models.CharField(max_length=100)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
gender = models.CharField(max_length=6, blank=True, null=True)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/275c600e-1e9a-4529-8ee1-3c7b4e2d8b60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django rest framework import data from one table to another

2018-01-04 Thread cherngyorng
I am doing a django rest framework API for ios application. And currently, 
i am doing a function between user and family.
Let me explain my logic between these two. 

User= current user (an account that can be use to login)
Family = current user's family member eg:father mother (it is not an 
account, cannot be use to sign in)

What i am thinking right now is that if the current user's family wanted to 
create an account, is it possible to import the data from family table to 
user table for that family member to register ?

Example scenario : 
user table : userId, username, password, email, phone_number, 
identification_num, first_name, last_name
family table :Id, userId(foreign key to user table, cannot be null) , 
familyId(can be null, reason is to allow user to add family member that did 
not register an account), phone_number, identification_num, first_name, 
last_name, relationship

Is it possible for user to sent invitation link to that family member, and 
it will import the data to the family member to register an account
- family member click on invite link
- redirect to register page with the detail from family table.
- If register success, insert the userId of that family member into 
familyId of family table.
- that family member account's family table will also update to have a 
family data with the current user.

Did i explain it clearly ? Sorry if it is not, you can tell me if it is not 
clear enough so i can try to make it clearer.
Is this kind of design good ? It seems like it has alot of flaw. 
Is it possible to import all that information into that invite register 
page ?

-- 
You received this message because you are subscribed to the Google 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/33e778de-c30b-4194-bf6e-bfba5e1e7c5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin Form clean method override only working for one exception

2018-01-04 Thread dean raemaekers
Thanks Julio!

This worked.

On Thursday, January 4, 2018 at 2:59:16 PM UTC+2, Julio Biason wrote:
>
> Hi Dean,
>
> You forgot to call the form clean method (the first line after your `def 
> clean` should be `super().clean()` as shown in the documentation: 
> https://docs.djangoproject.com/en/2.0/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
> ).
>
> On Thu, Jan 4, 2018 at 7:06 AM, dean raemaekers  > wrote:
>
>> Hello,
>>
>> I am trying to override the Forms in the Django Admin interface to have 
>> custom exceptions in the clean() method.
>>
>> This works for my first validation, but it doesn't work for a second one 
>> in the same form, or on another form at all. I am wondering if I have the 
>> syntax wrong for multiple validations.
>>
>> The code looks like this:
>>
>> class ProviderForm(forms.ModelForm):
>> class Meta:
>> model = Provider
>> fields = '__all__'
>>
>> def clean(self):
>> #provider start date and end date
>> provider_start_date = self.cleaned_data.get('provider_start_date')
>> provider_end_date = self.cleaned_data.get('provider_end_date')
>> if provider_start_date > provider_end_date:
>> raise forms.ValidationError("Start date can't be after end date")
>>
>> #etqe_id and provider_code
>> provider_etqe_id = self.cleaned_data.get('provider_etqe_id')
>> provider_code = self.cleaned_data.get('provider_code')
>> if "HW" not in provider_code:
>> raise forms.ValidationError("Invalid provider code")
>>
>> if "9" not in provider_etqe_id:
>> raise forms.ValidationError("Invalid ETQE ID") 
>>
>> return self.cleaned_data
>>
>> class ProviderAdmin(admin.ModelAdmin):
>> form = ProviderForm
>>
>> admin.site.register(Provider, ProviderAdmin)
>>
>> (The first validation, the start date and end date, does work perfectly - 
>> the second validation does not work at all, and allows the form to be saved 
>> no matter what data is entered)
>>
>> Then I also have replicated this for another form:
>>
>> class PersonForm(forms.ModelForm):
>> class Meta:
>> model = Person
>> fields = '__all__'
>>
>> def clean(self):
>>
>> person_alternate_id = self.cleaned_data.get('person_alternate_id')
>> alternate_id_type_id = self.cleaned_data.get('alternate_id_type_id') 
>>
>> if person_alternate_id is not None and alternate_id_type_id == 533:
>> raise forms.ValidationError("Person Alternate ID is not blank, therefore 
>> Alternate ID Type ID cannot be 533")
>> if person_alternate_id is None and alternate_id_type_id != 533:
>> raise forms.ValidationError("Person Alternate ID is blank, therefore 
>> Alternate ID Type ID must be 533")
>>
>> return self.cleaned_data
>>
>> class PersonAdmin(admin.ModelAdmin):
>> form = PersonForm
>>
>> admin.site.register(Person, PersonAdmin)
>>
>> This does not work at all, and also allows the form to be saved even if 
>> the invalid data has been entered.
>>
>> Thanks 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...@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/6d1e21bc-cc16-42bd-a9b9-949a800c81b7%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *Julio Biason*, Sofware Engineer
> *AZION*  |  Deliver. Accelerate. Protect.
> Office: +55 51 3083 8101  |  Mobile: +55 51 *99907 0554*
>

-- 
You received this message because you are subscribed to the Google 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/4cf452a6-1232-43d6-9ae0-1ddd310db98e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django rest framework viewset and its url

2018-01-04 Thread Dylan Reinhold
That link is not valid, and without seeing your views no one will be able
to help.

Dylan

On Thu, Jan 4, 2018 at 7:18 PM,  wrote:

> For a better and more detailed question i ask, refer to here :
> https://stackoverflow.com/questions/48106733/django-
> rest-framework-viewset-and-url-mixup
>
> In my project, i have 2 model. family and schedule
>
> As i wanted to have 1 api to get all while the other is to get current
> user only therefore i create 2 viewset for each serializer.
> I also specify different url based on the different viewset i created.
>
> eg: router = routers.DefaultRouter()
>
> router.register(r'Family', views.FamilyViewSet)
> router.register(r'Schedule2', views.ScheduleViewSet2)
> router.register(r'CFamily', views.FamilyViewSet2)
> router.register(r'Schedule', views.ScheduleViewSet)
>
> However, only the schedule works properly while family uses FamilyViewSet2 
> for both in the API.
>
> I'm confuse about this problem, please help
>
> --
> You received this message because you are subscribed to the Google 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/9388e16f-fae4-48e2-b860-1b1cb5d0b502%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/CAHtg44CVPR4%3DXSNdDM3sNXxgWE3GYsPzS%2BJJr5nuOk%2B0FKOkKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to set up polls/admin url in Django Tutorial pt 2

2018-01-04 Thread Luna Tuna
I resolved this by observing that the admin stuff for an app shows up on 
mainsite/admin once registered in admin.py.  

-- 
You received this message because you are subscribed to the Google 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/de0cef24-10ae-4807-a3a5-ed628947fb54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django rest framework viewset and its url

2018-01-04 Thread cherngyorng
For a better and more detailed question i ask, refer to here 
: 
https://stackoverflow.com/questions/48106733/django-rest-framework-viewset-and-url-mixup

In my project, i have 2 model. family and schedule

As i wanted to have 1 api to get all while the other is to get current user 
only therefore i create 2 viewset for each serializer.
I also specify different url based on the different viewset i created.

eg: router = routers.DefaultRouter()

router.register(r'Family', views.FamilyViewSet)
router.register(r'Schedule2', views.ScheduleViewSet2)
router.register(r'CFamily', views.FamilyViewSet2)
router.register(r'Schedule', views.ScheduleViewSet)

However, only the schedule works properly while family uses FamilyViewSet2 for 
both in the API. 

I'm confuse about this problem, please help

-- 
You received this message because you are subscribed to the Google 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/9388e16f-fae4-48e2-b860-1b1cb5d0b502%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 2.0 throws AttributeError: ''Image' object has no attribute 'replace'"

2018-01-04 Thread Ari Kanevsky
https://stackoverflow.com/questions/48106161/django-2-0-throws-attributeerror-image-object-has-no-attribute-replace

-- 
You received this message because you are subscribed to the Google 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/1a8a8b45-2f85-469d-ab76-caa273dd0fd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to make a place where you could type in data(number)?

2018-01-04 Thread June Kim
I'm looking for a way to set up a place(square box) where you could input 
data(number) on a website. and those data would be saved in somewhere else 
as an excel sheet (.csv)

-- 
You received this message because you are subscribed to the Google 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/f177be88-4911-4e9d-ac8e-66565aff3d32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to set up polls/admin url in Django Tutorial pt 2

2018-01-04 Thread Luna Tuna
Here's the tutorial 
.

It doesn't seem to mention after editing polls/admin.py how you set up the 
urls.  

So I'm getting page not found when I goto http://127.0.0.1:8000/polls/admin

My polls index page works and displays the hello world text.

Thank you!


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f7bf334-2c60-43bd-9208-17e0a3c3ea8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Send Activation code in the email

2018-01-04 Thread Slc Rockers
as we see in some website ..when we register it sends activation code of 
5/6 alphanumeric character and when we enter the code our accounts get 
activated...
i am using "Djoser" with "django-rest-framework".. and djoser sends 
activation url for activation...what should i do for activation code rather 
than activation url

-- 
You received this message because you are subscribed to the Google 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/0833e603-943e-4aa3-973c-d40f674d5b1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get ModelAdmin given a Model

2018-01-04 Thread Edouard C.

'type(v)' is model..instead of 'v is model' works,
in case not too late for someone else...
thanks Matt..

def get_admin(model):
for k,v in admin.site._registry.iteritems():

if type(v) is model:
return v


On Monday, January 11, 2010 at 9:37:47 PM UTC, Matt Schinckel wrote:
>
> On Jan 12, 4:11 am, Tomasz ZieliƄski
>  wrote:
> > On 11 Sty, 16:23, Marco Rogers  wrote:
> >
> > > I'm reposting this from earlier to see if I have better luck. I need
> > > to be able to get the ModelAdmin associated with a model at runtime.
> > > Similar to how django.db.models.get_model allows you to retrieve a
> > > model.
> >
> > > admin_class = get_admin(Model)
> >
> > > Is this possible?
> >
> > > The original post has more info.
> >
> > >http://groups.google.com/group/django-users/browse_thread/thread/0cd0.
> ..
> >
> > Maybe something like this:
> >
> > 1. Write something like django.contrib.admin.autodiscover, to get all
> > ModelAdmins
> > 2. Iterate those ModelAdmins, retrieve models they are attached to and
> > store this mapping in a dict.
> > 3. def get_admin(model):
> > return admin_to_model[model]
>
> You should be able to iterate through admin.site._registry, and pull
> out the one you need.
>
> from django.contrib import admin
> def get_admin(model):
> for k,v in admin.site._registry.iteritems():
> if v is model:
> return v
>
> Written in a browser.
>
> Matt.
>
>

-- 
You received this message because you are subscribed to the Google 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/8f5d1af4-3792-44f6-b8a4-f0fc1dbf8b6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Split API URLs to second project/settings/wsgi ?

2018-01-04 Thread guettli


Am Mittwoch, 3. Januar 2018 17:40:51 UTC+1 schrieb Jason:
>
> Sounds like this is a good use case to integrate DRF to solve multiple 
> problems.
>
>
>
I am unsure. I would like to have auth solved by the framework. With 
framework I mean django.

-- 
You received this message because you are subscribed to the Google 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/4d127ad9-3cb3-4fbd-88fd-cbcebcc5ffd6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Scope of Django

2018-01-04 Thread Julio Biason
Hi Sidharth,

What do you mean by "scope"? Django is the backend and templating engine
(in the backend, not frontend like React/Vue/Preact). You can basically
write the whole "store data" part in Django, with the presentation on top
of it and add some interaction with the user with JavaScript (manually).

About documentation, if you never used Django before, I'd suggestion going
through the project tutorials (https://docs.djangoproject.com/en/2.0/intro/)
before anything.

On Thu, Jan 4, 2018 at 9:18 AM, Sidharth Rai 
wrote:

> Hello,
>
> What is the scope of Django over JavaScript?
>
> Can anyone suggest me some good online tutorials for Django for building
> web apps?
>
> Thank You.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/8eace426-82b4-4bb3-8f02-27df952aa866%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

-- 
You received this message because you are subscribed to the Google 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/CAEM7gE1X74JZsXOzjkW-GVzHuA%3D8gM-L2mWNPJzkWz%2BG_cLmBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin Form clean method override only working for one exception

2018-01-04 Thread Julio Biason
Hi Dean,

You forgot to call the form clean method (the first line after your `def
clean` should be `super().clean()` as shown in the documentation:
https://docs.djangoproject.com/en/2.0/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
).

On Thu, Jan 4, 2018 at 7:06 AM, dean raemaekers 
wrote:

> Hello,
>
> I am trying to override the Forms in the Django Admin interface to have
> custom exceptions in the clean() method.
>
> This works for my first validation, but it doesn't work for a second one
> in the same form, or on another form at all. I am wondering if I have the
> syntax wrong for multiple validations.
>
> The code looks like this:
>
> class ProviderForm(forms.ModelForm):
> class Meta:
> model = Provider
> fields = '__all__'
>
> def clean(self):
> #provider start date and end date
> provider_start_date = self.cleaned_data.get('provider_start_date')
> provider_end_date = self.cleaned_data.get('provider_end_date')
> if provider_start_date > provider_end_date:
> raise forms.ValidationError("Start date can't be after end date")
>
> #etqe_id and provider_code
> provider_etqe_id = self.cleaned_data.get('provider_etqe_id')
> provider_code = self.cleaned_data.get('provider_code')
> if "HW" not in provider_code:
> raise forms.ValidationError("Invalid provider code")
>
> if "9" not in provider_etqe_id:
> raise forms.ValidationError("Invalid ETQE ID")
>
> return self.cleaned_data
>
> class ProviderAdmin(admin.ModelAdmin):
> form = ProviderForm
>
> admin.site.register(Provider, ProviderAdmin)
>
> (The first validation, the start date and end date, does work perfectly -
> the second validation does not work at all, and allows the form to be saved
> no matter what data is entered)
>
> Then I also have replicated this for another form:
>
> class PersonForm(forms.ModelForm):
> class Meta:
> model = Person
> fields = '__all__'
>
> def clean(self):
>
> person_alternate_id = self.cleaned_data.get('person_alternate_id')
> alternate_id_type_id = self.cleaned_data.get('alternate_id_type_id')
>
> if person_alternate_id is not None and alternate_id_type_id == 533:
> raise forms.ValidationError("Person Alternate ID is not blank, therefore
> Alternate ID Type ID cannot be 533")
> if person_alternate_id is None and alternate_id_type_id != 533:
> raise forms.ValidationError("Person Alternate ID is blank, therefore
> Alternate ID Type ID must be 533")
>
> return self.cleaned_data
>
> class PersonAdmin(admin.ModelAdmin):
> form = PersonForm
>
> admin.site.register(Person, PersonAdmin)
>
> This does not work at all, and also allows the form to be saved even if
> the invalid data has been entered.
>
> Thanks in advance!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/6d1e21bc-cc16-42bd-a9b9-949a800c81b7%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

-- 
You received this message because you are subscribed to the Google 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/CAEM7gE0s%2BVYVknpZ3wj%3DdCqh%2BAwM6kB%3D-9joA8xdu-4PhXqJ-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Scope of Django

2018-01-04 Thread Sidharth Rai
Hello,

What is the scope of Django over JavaScript?

Can anyone suggest me some good online tutorials for Django for building 
web apps?

Thank You.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8eace426-82b4-4bb3-8f02-27df952aa866%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Admin Form clean method override only working for one exception

2018-01-04 Thread dean raemaekers
Hello,

I am trying to override the Forms in the Django Admin interface to have 
custom exceptions in the clean() method.

This works for my first validation, but it doesn't work for a second one in 
the same form, or on another form at all. I am wondering if I have the 
syntax wrong for multiple validations.

The code looks like this:

class ProviderForm(forms.ModelForm):
class Meta:
model = Provider
fields = '__all__'

def clean(self):
#provider start date and end date
provider_start_date = self.cleaned_data.get('provider_start_date')
provider_end_date = self.cleaned_data.get('provider_end_date')
if provider_start_date > provider_end_date:
raise forms.ValidationError("Start date can't be after end date")

#etqe_id and provider_code
provider_etqe_id = self.cleaned_data.get('provider_etqe_id')
provider_code = self.cleaned_data.get('provider_code')
if "HW" not in provider_code:
raise forms.ValidationError("Invalid provider code")

if "9" not in provider_etqe_id:
raise forms.ValidationError("Invalid ETQE ID") 

return self.cleaned_data

class ProviderAdmin(admin.ModelAdmin):
form = ProviderForm

admin.site.register(Provider, ProviderAdmin)

(The first validation, the start date and end date, does work perfectly - 
the second validation does not work at all, and allows the form to be saved 
no matter what data is entered)

Then I also have replicated this for another form:

class PersonForm(forms.ModelForm):
class Meta:
model = Person
fields = '__all__'

def clean(self):

person_alternate_id = self.cleaned_data.get('person_alternate_id')
alternate_id_type_id = self.cleaned_data.get('alternate_id_type_id') 

if person_alternate_id is not None and alternate_id_type_id == 533:
raise forms.ValidationError("Person Alternate ID is not blank, therefore 
Alternate ID Type ID cannot be 533")
if person_alternate_id is None and alternate_id_type_id != 533:
raise forms.ValidationError("Person Alternate ID is blank, therefore 
Alternate ID Type ID must be 533")

return self.cleaned_data

class PersonAdmin(admin.ModelAdmin):
form = PersonForm

admin.site.register(Person, PersonAdmin)

This does not work at all, and also allows the form to be saved even if the 
invalid data has been entered.

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6d1e21bc-cc16-42bd-a9b9-949a800c81b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django storing byte string for image

2018-01-04 Thread Shem Ogumbe
Maybe try the conversion then save the path to MongoDb, but not the 
bytsetring itself

On Wednesday, January 3, 2018 at 3:03:36 PM UTC+3, chern...@gmail.com wrote:
>
> What field should i use to store byte string so that i can later use it 
> for ByteIO to convert it into image ?
>
> As this is my first time doing on byte string to image, i am pretty lost 
> on what i need to do.
>
> I tried using BinaryField for the image model but when checking the field 
> out on Django admin, it gave me this error
> 'image' cannot be specified for MyUser model form as it is a non-editable 
> field
> i also tried setting BinaryField(editable=True) but it still doesnt work.
>
> May i have some guidance on how to store the byte string ? 
>

-- 
You received this message because you are subscribed to the Google 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/b7bc5c1f-0a43-4d71-aa83-a0c4fc610232%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to delete all the objects which are referring the current object without DELETE_CASCADE

2018-01-04 Thread James Schneider
On Jan 3, 2018 4:29 AM, "Jani Tiainen"  wrote:

Hi,

As I posted on other thread you can do that using meta api.

But why you want to do that manually. DELETE_CASCADE does the same thing
exactly.



While I don't know the motivations of the OP, one reason you may want to do
this is for auditing purposes. There may be a requirement to track
additions and removals of records. I don't think a cascade delete would
capture enough information in such a case, even with a high level of
transaction logging.

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUtvGbtJt-kpDgv-muDnv7wgnDna9dhONfN%2BpJH8T-FmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to delete all the objects which are referring the current object without DELETE_CASCADE

2018-01-04 Thread Shem Ogumbe

Question is, why do that when on_delete=models.CASACADE is there to do it 
for you?


On Wednesday, January 3, 2018 at 3:03:36 PM UTC+3, mohitdu...@gmail.com 
wrote:
>
> How to delete all the objects which are referring the current object 
> without DELETE_CASCADE
>

-- 
You received this message because you are subscribed to the Google 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/5dfd9439-c908-4360-b8c3-df4d288f45a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django storing byte string for image

2018-01-04 Thread cherngyorng

>
> From the requirement i get, i am suppose to store the bytestring into another 
> db. Main db is using postgresql, the image however is save to path into 
> mongodb.
>
> and yes,  the image im recieving is in byte string. Thank you guys for 
your help ! I'm going to try it out locally first

-- 
You received this message because you are subscribed to the Google 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/596bb647-43ab-41de-912d-0e3c3b1c9ba4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django storing byte string for image

2018-01-04 Thread Shem Geek


On Wednesday, January 3, 2018 at 3:03:36 PM UTC+3, chern...@gmail.com wrote:
>
> What field should i use to store byte string so that i can later use it 
> for ByteIO to convert it into image ?
>
> As this is my first time doing on byte string to image, i am pretty lost 
> on what i need to do.
>
> I tried using BinaryField for the image model but when checking the field 
> out on Django admin, it gave me this error
> 'image' cannot be specified for MyUser model form as it is a non-editable 
> field
> i also tried setting BinaryField(editable=True) but it still doesnt work.
>
> May i have some guidance on how to store the byte string ? 
>


Whether stored as bytestrings or images, it is a bad practice to store 
images in the database.
I believe from the problem description that what you are trying to 
acomplish is store images which you receive in the form of a bytestring.
Have you considered converting the bytestring to an image and storing the 
image in file system using normal imageField:
It would be something like this:


 import base64
 def _construct_image(bytestring):
img = open("imageToSave.png", "wb")
img.write(str.decode('base64'))
img.close()




In your django models, you use this function to convert the bytestring to an 
image and store where upload_to
 wants to store it.
Suppose you choose to overide the save method to handle the handle the 
conversion, that will be something like:

def save(self, *args, **kwargs):

image = _construct_image(self.image)

return Super(YourModel, self).save(*args, **kwargs)



Check if it works.

-- 
You received this message because you are subscribed to the Google 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/63d4b946-3b58-44c6-94c1-f61c9a91abaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.