Re: Newbie : Object copy - weird error :-)

2018-07-13 Thread mickael . barbo
Thanks you Melvyn, this is it :-)

Have a nice day.

Regards

Le mardi 3 juillet 2018 00:34:14 UTC+2, Melvyn Sopacua a écrit :
>
> On vrijdag 29 juni 2018 09:44:40 CEST Mickael Barbo wrote:
>
>  
>
> > I try to create a way to archive (copy) the same object instance on an
>
> > other DataBase.
>
> > 
>
> > I followed this advice : # https://stackoverflow.com/
>
> > questions/21699707/python-how-to-copy-all-attibutes-from-
>
> > base-class-to-derived-one
>
>  
>
> That advice is for normal python classes. Django models have some 
> restrictions, one being that fields are special attributes. Messing with a 
> model's __init__() is not something you normally do as a model's class 
> creation is highly customized.
>
>  
>
> If you're really using 2 different databases, a model's save() operation 
> supports a `using` keyword that allows you to select the database 
> connection 
> .
>  
> Archiving becomes really easy that way.
>
>  
>
>  
>
> -- 
>
> Melvyn Sopacua
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a3f21016-62ab-43cc-9c3a-164797a602c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weighing Scale & TCP IP connectivity

2018-07-13 Thread mottaz hejaze
check this

https://raspberrypi.stackexchange.com/questions/70476/tcp-communication-raspberry-pi-and-pc-via-ethernet


On Fri, 13 Jul 2018, 11:08 mottaz hejaze,  wrote:

> you dont need sockets , you can make the weight program scan inputs every
> n seconds .. or you can program it to be an event hundler to any  change in
> unputs
>
> start with weight program , design it the code it . test untill you
> satisfied .. now you can do the connection with backend in many ways ..
>
> you can make your program connect to the same database that your django
> has access to it
>
> you can record in csv or json files and send them to django as Tom
> mentioned maybe try to use django rest for hundling json requests and
> responses
>
> also you can make the program embedded in your backend django as a module
> or a script
>
>
>
> On Thu, 12 Jul 2018, 21:09 Thomas G Lockhart, 
> wrote:
>
>> You can use Django REST framework to get data into Django and a separate
>> Python (or other) program to feed it in. Have the Python program connect to
>> the scale and use whatever mechanisms are required there to get your data.
>>
>> If the scale has a browser interface, then use urllib to read a page and
>> then use BeautifulSoup to rummage through it and pick out the weight etc.
>> Then push it using json into your REST endpoint.
>>
>> hth
>>
>> - Tom
>>
>>
>> On Jul 11, 2018, at 11:26 PM, ERICK OMONDI AYARA 
>> wrote:
>>
>> Hello, I would like to capture weight from a weighing scale using
>> TCP/Ethernet cable into a django app. If anyone can advice on how to use
>> sockets or any other means to make this work, will be appreciated. Regards
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "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/ee33e49e-67d5-491a-a113-09fbd5290d56%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/FEBBB7C6-7CF7-4E11-9372-ED957E4AD0DF%40gmail.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/CAHV4E-dWPk4OxNekqyk-fBLJBHRk5TU9pV%2BnzOrfrj8_Soh3jg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Weighing Scale & TCP IP connectivity

2018-07-13 Thread mottaz hejaze
you dont need sockets , you can make the weight program scan inputs every n
seconds .. or you can program it to be an event hundler to any  change in
unputs

start with weight program , design it the code it . test untill you
satisfied .. now you can do the connection with backend in many ways ..

you can make your program connect to the same database that your django has
access to it

you can record in csv or json files and send them to django as Tom
mentioned maybe try to use django rest for hundling json requests and
responses

also you can make the program embedded in your backend django as a module
or a script



On Thu, 12 Jul 2018, 21:09 Thomas G Lockhart, 
wrote:

> You can use Django REST framework to get data into Django and a separate
> Python (or other) program to feed it in. Have the Python program connect to
> the scale and use whatever mechanisms are required there to get your data.
>
> If the scale has a browser interface, then use urllib to read a page and
> then use BeautifulSoup to rummage through it and pick out the weight etc.
> Then push it using json into your REST endpoint.
>
> hth
>
> - Tom
>
>
> On Jul 11, 2018, at 11:26 PM, ERICK OMONDI AYARA 
> wrote:
>
> Hello, I would like to capture weight from a weighing scale using
> TCP/Ethernet cable into a django app. If anyone can advice on how to use
> sockets or any other means to make this work, will be appreciated. Regards
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/ee33e49e-67d5-491a-a113-09fbd5290d56%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/FEBBB7C6-7CF7-4E11-9372-ED957E4AD0DF%40gmail.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/CAHV4E-fKY1bA5RD7b13zOw%3DqsjGv6AiVFiisV5r2siDfD-nG_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


App structure : "One file - One object" - Is there a better way ?

2018-07-13 Thread Mickael Barbo
Hi !

*I like working with " 1 file - 1 object " (Object could be class,
function...).*
It simplify visibility, debug etc... and it's easy for me to *don't pollute
my brain* :-)


For exemple, I do :


In *class_.py file* :

class ():
a
b
c

from ._method1 import method1
from ._method2 import method2



and in *_method1.py file* :

def method1(self):
"my code"




*It works great, but is there a better way to do that ? is there a solution
to do that "automatically" ?*



I read lots of thinks about mixin, heritage, etc... but is there a better
way to split code to get a better granularity ?


Thanks for sharing your point ;-)

-- 
You received this message because you are subscribed to the Google Groups 
"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/CAPLHwtyEAuCs1UcvLTzt1sXL7jpCQH%3DD_TGBgwiqbq7svc%3DNaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to insert fullcalendar object in django admin?

2018-07-13 Thread Jhon Carrillo
Hi Folks,
I would like to know if someone in this group has inserted fullcalendar 
(https://fullcalendar.io/) in django admin. Is this possible?
Thank you for your comments,
Jhon

-- 
You received this message because you are subscribed to the Google Groups 
"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/6edeb751-752c-45f2-8927-0e5b0960b649%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Upgrading Django

2018-07-13 Thread Ghiath ghanem
I'm working on small project, (Automatic Calender for the near future 
events from Tweets).
I have upgraded to Python 3.4.3, and Now i would like to upgrade Django 
from 1.5.11 to 2.0.7.
Almost everything went well until  i got this error:
?: (admin.E402) 'django.contrib.auth.context_processors.auth' must be in 
TEMPLATES in order to use the admin application.
can anyone help me?


-- 
You received this message because you are subscribed to the Google Groups 
"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/2ee31f9a-7858-49fe-832b-f3595af67e75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django how to go about using npm modules with static/ templates

2018-07-13 Thread HashRocketSyntax


I have recently added *npm* to my project in order to keep better track of 
my js dependencies. Previously I have just been git cloning to my 
static/vendor folder.

I've also added *gulp* , but have only got it doing hello world things 
right now. It seems simple enough - it can watch files, minify assets, 
compile Sass. Eventually I will probably switch to *Webpack*, but gulp is 
simple and working for now. I don't want to use *django-compressor* or 
*django-pipeline*.

--

So let's say I run npm install vis to pull in visjs. It gets added to 
node_modulesand a record is added to package.json dependencies.


*A)* Do I reference vis/dist right where it is in node_mods in my template 
scripts?


# right now it's 

Re: formaction vs get_absolute_url

2018-07-13 Thread Daniel Roseman
On Thursday, 12 July 2018 21:04:25 UTC+1, clavie...@gmail.com wrote:
>
> I'm looking for a way to redirect to a different page depending upon which 
> submit button the user clicks. I included a formaction tag in the template, 
> but django still demands that get_absolute_url be defined. Using Django 2.0
>
> Basically, I'm trying to write a small app that launches a test case, 
> which would allow a non-programmer to evaluate a small section of code 
> responsible for a background process. The app should allow the user to add 
> as many test items to it as they wish, one at a time. When an item is 
> added, they can choose to click and 'evaluate' button or an 'add more 
> items' button, and each button should go to a different page--basically, 
> 'add more items' should refresh the same page. Clicking on 'add more items' 
> does indeed post the data to the database, but it ignores the formaction 
> tag. The stack trace says that form_valid is calling get_absolute_url on 
> the model (which I have not defined), but the target url has to do with 
> what the user wants to do next with said model, not the model itself. I 
> haven't figured out how to override the get_absolute_url call based on 
> which html button was clicked. (Though it also said I can provide an url, 
> which I did on the template...)
>
> (The code I'm pasting below may be a little awkward because I've been 
> finding workarounds for things by trial and error; so if anything 
> particularly egregious catches someone's eye, comments to that end are 
> welcome.)
>


You've misdiagnosed the problem. formaction is working fine; the data is 
being posted to your add-items view. The issue is what happens next. Any 
successful POST should be followed by a redirect, and CreateView by default 
uses the value of get_absolute_url to determine where to direct to.

Actually, formaction isn't what you want here at all. You've almost 
mentioned the solution by talking about overriding get_absolute_url based 
on the HTML button; that's not quite it, what you actually need to do is to 
override the method responsible for calling it, which is the view's 
get_success_url.

class AddItemsToEvaluateCreateView(CreateView):
...
def get_success_url(self):
if 'add_more' in self.request.POST:
return reverse('evaluate', kwargs={'pk': self.kwargs['pk']}
elif 'optimize' in self.request.POST:
return reverse('results', kwargs={'pk': self.kwargs['pk']}
return '/'


Also you'll need to change your input elements; they don't need 
`formaction`, but they do need a `name` so that they are sent in the POST 
data:




--
DR.

>

-- 
You received this message because you are subscribed to the Google Groups 
"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/6e1cd862-f528-4b0b-bd91-53530c904d31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Upgrading Django

2018-07-13 Thread mottaz hejaze
please share your settings.py . maybe you need to add or edit some
middleware in settings.py

On Fri, 13 Jul 2018, 14:36 Ghiath ghanem,  wrote:

> I'm working on small project, (Automatic Calender for the near future
> events from Tweets).
> I have upgraded to Python 3.4.3, and Now i would like to upgrade Django
> from 1.5.11 to 2.0.7.
> Almost everything went well until  i got this error:
> ?: (admin.E402) 'django.contrib.auth.context_processors.auth' must be in
> TEMPLATES in order to use the admin application.
> can anyone help me?
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/2ee31f9a-7858-49fe-832b-f3595af67e75%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/CAHV4E-dtqy3eRQ%3Dx6jEVR3xQDBBEwYruFmDv1e0dWYe7UE3A0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to insert fullcalendar object in django admin?

2018-07-13 Thread john fabiani

I think this uses fullcalendar.io - could be wrong

https://github.com/dakrauth/django-swingtime

Johnf


On 07/13/2018 01:37 AM, Jhon Carrillo wrote:

Hi Folks,
I would like to know if someone in this group has inserted 
fullcalendar (https://fullcalendar.io/) in django admin. Is this possible?

Thank you for your comments,
Jhon
--
You received this message because you are subscribed to the Google 
Groups "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/6edeb751-752c-45f2-8927-0e5b0960b649%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/417a329b-1187-8d06-ec84-aca7db2d3dbe%40jfcomputer.com.
For more options, visit https://groups.google.com/d/optout.


Re: formaction vs get_absolute_url

2018-07-13 Thread clavierplayer
Thank you for the clear explanation! It works beautifully now.

On Friday, July 13, 2018 at 9:17:37 AM UTC-4, Daniel Roseman wrote:
>
> On Thursday, 12 July 2018 21:04:25 UTC+1, clavie...@gmail.com wrote:
>>
>> I'm looking for a way to redirect to a different page depending upon 
>> which submit button the user clicks. I included a formaction tag in the 
>> template, but django still demands that get_absolute_url be defined. Using 
>> Django 2.0
>>
>> Basically, I'm trying to write a small app that launches a test case, 
>> which would allow a non-programmer to evaluate a small section of code 
>> responsible for a background process. The app should allow the user to add 
>> as many test items to it as they wish, one at a time. When an item is 
>> added, they can choose to click and 'evaluate' button or an 'add more 
>> items' button, and each button should go to a different page--basically, 
>> 'add more items' should refresh the same page. Clicking on 'add more items' 
>> does indeed post the data to the database, but it ignores the formaction 
>> tag. The stack trace says that form_valid is calling get_absolute_url on 
>> the model (which I have not defined), but the target url has to do with 
>> what the user wants to do next with said model, not the model itself. I 
>> haven't figured out how to override the get_absolute_url call based on 
>> which html button was clicked. (Though it also said I can provide an url, 
>> which I did on the template...)
>>
>> (The code I'm pasting below may be a little awkward because I've been 
>> finding workarounds for things by trial and error; so if anything 
>> particularly egregious catches someone's eye, comments to that end are 
>> welcome.)
>>
>
>
> You've misdiagnosed the problem. formaction is working fine; the data is 
> being posted to your add-items view. The issue is what happens next. Any 
> successful POST should be followed by a redirect, and CreateView by default 
> uses the value of get_absolute_url to determine where to direct to.
>
> Actually, formaction isn't what you want here at all. You've almost 
> mentioned the solution by talking about overriding get_absolute_url based 
> on the HTML button; that's not quite it, what you actually need to do is to 
> override the method responsible for calling it, which is the view's 
> get_success_url.
>
> class AddItemsToEvaluateCreateView(CreateView):
> ...
> def get_success_url(self):
> if 'add_more' in self.request.POST:
> return reverse('evaluate', kwargs={'pk': self.kwargs['pk']}
> elif 'optimize' in self.request.POST:
> return reverse('results', kwargs={'pk': self.kwargs['pk']}
> return '/'
>
>
> Also you'll need to change your input elements; they don't need 
> `formaction`, but they do need a `name` so that they are sent in the POST 
> data:
>
> 
> 
>
> --
> DR.
>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"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/a47aef1d-0dcd-4d35-9f0f-aaa0ba43c8ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Static images are working but static CSS is not working SS attached

2018-07-13 Thread Param Saini
Static Images are working perfectly in Django .. but when i try to use 
static CSS or evev open Django admin panel . CSS is not implemented there 

please help on priority

-- 
You received this message because you are subscribed to the Google Groups 
"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/cbdb24b2-bee1-4346-b047-b59ff08a3c57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Upgrading Django

2018-07-13 Thread Derek
See:

https://docs.djangoproject.com/en/1.10/ref/templates/upgrading/


On Friday, 13 July 2018 14:36:52 UTC+2, Ghiath ghanem wrote:
>
> I'm working on small project, (Automatic Calender for the near future 
> events from Tweets).
> I have upgraded to Python 3.4.3, and Now i would like to upgrade Django 
> from 1.5.11 to 2.0.7.
> Almost everything went well until  i got this error:
> ?: (admin.E402) 'django.contrib.auth.context_processors.auth' must be in 
> TEMPLATES in order to use the admin application.
> can anyone help me?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/c0e94429-f509-4109-bc72-1b771c46ff31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Static images are working but static CSS is not working SS attached

2018-07-13 Thread Kasper Laudrup

Hi Param,

On 2018-07-13 16:29, Param Saini wrote:
Static Images are working perfectly in Django .. but when i try to use 
static CSS or evev open Django admin panel . CSS is not implemented there




Are you running the development server or is this in production?

If it is in production, have you set up your web server to serve the 
static files correctly, added the necessary settings to settings.py and 
run the 'collectstatic' command?


There's quite a lot of documentation on how to server static files in 
production out there. A simple google search should give you tons of hits.


If you need more help, please post your web server configuration as well 
as your settings.py file.


Kind regards,

Kasper Laudrup

--
You received this message because you are subscribed to the Google Groups "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/5b775bb4-41ee-6113-d8b5-160099d607b4%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


ModelForm: overriding is_valid()

2018-07-13 Thread clavierplayer
I have an Item model. It has both a primary key and an item number; the 
users refer to item numbers when finding things, and the actual primary key 
is not exposed. I'm trying to write a CreateView that will allow the user 
to input the item number. 

I see that CreateView defaults to using the primary key to find model 
objects, which any other time makes sense. I'm thinking the solution is to 
use a ModelForm, but I'm stuck on the same problem--I'm not sure how to 
accept a string from the user (instead of the primary key), do my own 
query, and fetch the required model object that way. I think overriding 
is_valid() is the correct way to go, but I'm not sure what I'm leaving 
out--when I override this method, the data is never committed to the 
database even though I call super(). I've also tried overriding save() and 
clean() on the ModelForm, but with the same results (that is, no data in 
the database). 

I'm writing a simple app that uses Item as a foreign key: 

class ItemsTestCollection(models.Model):
"""An item to be tested in Box Opt."""
item = models.ForeignKey('item.Item', on_delete=models.CASCADE)
qty = models.IntegerField()
case = models.ForeignKey('EvaluateTestCase', on_delete=models.CASCADE)
box = models.ForeignKey('BoxResults', on_delete=models.CASCADE, null=True)

...using this CreateView:

class AddItemsToEvaluateCreateView(CreateView):
model = ItemsTestCollection
form_class = AddItem
# fields = ['item', 'qty', 'case']
template_name = 'utils\evaluate.html'


# Not working...
def form_valid(self, form):
data = form.save(commit=False)
item_num = data.item
data.item = Item.objects.get(item_number=item_num)
data.save()

return self.get_success_url()


...and this ModelForm:

class AddItem(forms.ModelForm):

class Meta:
model = ItemsTestCollection
fields = ['item', 'qty', 'case']
# widgets = {'item': CharField(max_length=6)}

# item = forms.CharField(max_length=6)
def is_valid(self):
item_num = self.data['item']  # 
# self.data['item'] = Item.objects.get(item_number=item_num)
self.instance.item = Item.objects.get(item_number=item_num)
# self.instance.qty = self.data['qty']
# self.instance.case = 
EvaluateTestCase.objects.get(pk=self.data['case'])
super().is_valid()


And I somehow need to refer to the Item by item_number and not the 
auto-assigned pk:

class Item(models.Model):
"""Item attributes"""

item_number = models.CharField(max_length=6, null=True, unique=True)



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/5f4a4128-71f4-482a-b443-affe42fee109%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to solve it view app.views.register didn't return an HttpResponse object. It returned None instead.

2018-07-13 Thread abhishek dadhich
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm

class RegistrationForm(UserCreationForm):
email=forms.EmailField(required=True)

class Meta:
model=User
fields ={
'username',
'first_name',
'last_name',
'password1',
'email',
}
def save(self,commit=True):
user = super(RegistrationForm,self).save(commit=False)
user.fisrt_name=self.cleaned_data['first_name']
user.last_name=self.cleaned_data['last_name']
user.emil=self.email.cleaned_data['email']

if commit:
user.save()
return user
*This is my form.py file*


from django.shortcuts import render,redirect
from app.forms import RegistrationForm
from django.contrib.auth.forms import UserCreationForm
from django.http import HttpResponse
from django.views.generic import TemplateView
from django.template import loader

def register(request):
if request.method =='POST':
form=RegistrationForm(request.POST)
if form.is_valid():
form.save()
return redirect('home')
else:
form=RegistrationForm()

args={'form':form}
return render(request,'reg_form.html',args)
*And this is my view.py file*


*when I'm pressing the submit button it will show me "view 
app.views.register didn't return an HttpResponse object. It returned None 
instead"*

-- 
You received this message because you are subscribed to the Google Groups 
"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/11548a24-127a-46cf-866e-66cd96e6f178%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to solve it view app.views.register didn't return an HttpResponse object. It returned None instead.

2018-07-13 Thread Jason
if form.is_valid():
form.save()
return redirect('home')

You don't return anything when the form is invalid.  That's why it returns 
None

On Friday, July 13, 2018 at 3:31:43 PM UTC-4, abhishek dadhich wrote:
>
> from django import forms
> from django.contrib.auth.models import User
> from django.contrib.auth.forms import UserCreationForm
>
> class RegistrationForm(UserCreationForm):
> email=forms.EmailField(required=True)
>
> class Meta:
> model=User
> fields ={
> 'username',
> 'first_name',
> 'last_name',
> 'password1',
> 'email',
> }
> def save(self,commit=True):
> user = super(RegistrationForm,self).save(commit=False)
> user.fisrt_name=self.cleaned_data['first_name']
> user.last_name=self.cleaned_data['last_name']
> user.emil=self.email.cleaned_data['email']
>
> if commit:
> user.save()
> return user
> *This is my form.py file*
>
>
> from django.shortcuts import render,redirect
> from app.forms import RegistrationForm
> from django.contrib.auth.forms import UserCreationForm
> from django.http import HttpResponse
> from django.views.generic import TemplateView
> from django.template import loader
>
> def register(request):
> if request.method =='POST':
> form=RegistrationForm(request.POST)
> if form.is_valid():
> form.save()
> return redirect('home')
> else:
> form=RegistrationForm()
>
> args={'form':form}
> return render(request,'reg_form.html',args)
> *And this is my view.py file*
>
>
> *when I'm pressing the submit button it will show me "view 
> app.views.register didn't return an HttpResponse object. It returned None 
> instead"*
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"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/b11278f8-3b98-4731-a938-029775bb1cf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to solve it view app.views.register didn't return an HttpResponse object. It returned None instead.

2018-07-13 Thread Hambali Idrees Ibrahim
i think you can use
forms.is_valid():
not
form.is_valid():

it may work

On Fri, Jul 13, 2018 at 11:33 AM, Jason  wrote:

> if form.is_valid():
> form.save()
> return redirect('home')
>
> You don't return anything when the form is invalid.  That's why it returns
> None
>
> On Friday, July 13, 2018 at 3:31:43 PM UTC-4, abhishek dadhich wrote:
>>
>> from django import forms
>> from django.contrib.auth.models import User
>> from django.contrib.auth.forms import UserCreationForm
>>
>> class RegistrationForm(UserCreationForm):
>> email=forms.EmailField(required=True)
>>
>> class Meta:
>> model=User
>> fields ={
>> 'username',
>> 'first_name',
>> 'last_name',
>> 'password1',
>> 'email',
>> }
>> def save(self,commit=True):
>> user = super(RegistrationForm,self).save(commit=False)
>> user.fisrt_name=self.cleaned_data['first_name']
>> user.last_name=self.cleaned_data['last_name']
>> user.emil=self.email.cleaned_data['email']
>>
>> if commit:
>> user.save()
>> return user
>> *This is my form.py file*
>>
>>
>> from django.shortcuts import render,redirect
>> from app.forms import RegistrationForm
>> from django.contrib.auth.forms import UserCreationForm
>> from django.http import HttpResponse
>> from django.views.generic import TemplateView
>> from django.template import loader
>>
>> def register(request):
>> if request.method =='POST':
>> form=RegistrationForm(request.POST)
>> if form.is_valid():
>> form.save()
>> return redirect('home')
>> else:
>> form=RegistrationForm()
>>
>> args={'form':form}
>> return render(request,'reg_form.html',args)
>> *And this is my view.py file*
>>
>>
>> *when I'm pressing the submit button it will show me "view
>> app.views.register didn't return an HttpResponse object. It returned None
>> instead"*
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "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/b11278f8-3b98-4731-a938-029775bb1cf2%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/CAMqGfDGR2hRyGaGfgNSUPi-fzdtnya8ubcRe%2B-fG8jtaO9Z%3DLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to verify if is new record or update record on django template?

2018-07-13 Thread Derek
You can pass in the ID (primary key) of the object from the view to the 
template.

On Thursday, 12 July 2018 15:58:45 UTC+2, Fellipe Henrique wrote:
>
> How to verify if is new record or update record on django template? How 
> can i do that?
>
> 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/64a75763-cf28-4730-b62a-06a6a833f447%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to solve it view app.views.register didn't return an HttpResponse object. It returned None instead.

2018-07-13 Thread Melvyn Sopacua
On vrijdag 13 juli 2018 21:40:48 CEST Hambali Idrees Ibrahim wrote:
> i think you can use
> forms.is_valid():
> not
> form.is_valid():
> 
> it may work

No, it won't.
Jason diagnosed it correctly.

-- 
Melvyn Sopacua

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


How is MySQL syntax for a table changed if I had a ManyToManyField?

2018-07-13 Thread lissandrathegray
I tried for hours to get django's migrate/makemigrations function work but 
miserably couldn't so I created my tables in MySQL. Now I'm trying to add a 
ManyToManyField between 2 models but am not sure how the MySQL syntax is 
supposed to look like.

This is my current code:

from django.db import models

class Publication(models.Model):
title = models.CharField(max_length=30)

class Article(models.Model):
headline = models.CharField(max_length=100)

and I can create a table as follows in MySQL:

CREATE TABLE publication ( 
title varchar(30)
);
CREATE TABLE Article (
headline varchar(100),
);

I need to add the ManyToManyField like so: 
class Article(models.Model):
headline = models.CharField(max_length=100)
*publications = models.ManyToManyField(Publication)*

I'm really running low on time, could someone assist me with what the MySQL 
code is supposed to look like? I will be permanently in your debt.

-- 
You received this message because you are subscribed to the Google Groups 
"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/6f546243-23f0-4760-806b-9fff01d2afd7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ERROR - server - Error trying to receive messages: name 'txredisapi' is not defined

2018-07-13 Thread Andrew Godwin
What version of Channels are you using? It looks like you're trying to use
Channels 1 without Twisted redis support installed - did you try installing
the package it's asking for?

Andrew

On Thu, Jul 12, 2018 at 4:22 AM Hank Chu  wrote:

> 2018-07-12 17:35:08,070 - INFO - worker - Listening on channels
>> http.request, websocket.connect, websocket.disconnect, websocket.receive
>> 2018-07-12 17:35:08,072 - INFO - server - HTTP/2 support not enabled
>> (install the http2 and tls Twisted extras)
>> 2018-07-12 17:35:08,075 - INFO - server - Using native Twisted mode on
>> channel layer
>> 2018-07-12 17:35:08,075 - INFO - server - Listening on endpoint
>> tcp:port=80:interface=10.144.1.123
>> 2018-07-12 17:35:08,077 - ERROR - server - Error trying to receive
>> messages: name 'txredisapi' is not defined
>> 2018-07-12 17:35:13,079 - ERROR - server - Error trying to receive
>> messages: name 'txredisapi' is not defined
>
>
> Can someone help me to fix this problem?
>
> this my django's setting.py
>
>> redis_host = '10.144.1.123'
>> CHANNEL_LAYERS = {
>> "default": {
>> "BACKEND": "asgi_redis.RedisChannelLayer",
>> "CONFIG": {
>> "hosts": [(redis_host, 6379)],
>> },
>>"ROUTING": "coverage_wabsys_py3.routing.channel_routing",
>> },
>> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "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/e3405fbd-1f5a-407b-a18e-138f53a2fe6e%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/CAFwN1ur9nrWPJKu_rRhR_Cxve%3DeqFA7pr2NtX9bz8VCw9DhP1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing Django through ssh tunneling and error to get status

2018-07-13 Thread Robert Edward
Hey, uhm I faced a similar problem lately. Try this in the Settings.py
file,

Inside the brackets insert an asterisk ✳
It should look something like this

Allowed host = [ *];
Then try again.


On Thu, Jul 12, 2018, 7:34 PM Dikus Extrange 
wrote:

> Hi Jason. Thank you for your reply. I tried with your suggestion.
>
> Django complained about putting then name of my laptop and its domain in
> allowed hosts (I had to put 'localhost' and '127.0.0.1' before). So I put
> it in settings.py and the. Result is the same with the same message.
>
> El jueves, 12 de julio de 2018, 13:27:50 (UTC+2), Jason escribió:
>>
>> you should use *0.0.0.0* for the ip address rather than 127.0.0.1
>>
>> On Thursday, July 12, 2018 at 7:22:33 AM UTC-4, Dikus Extrange wrote:
>>>
>>> Hi everyone. I'm accessing to a Django application through a ssh tunnel
>>> with putty as client. I run the server with ./manage.py run server
>>> 127.0.0.1:8000 and it starts right but launching an infinite and
>>> annoying message:
>>>
>>> Not found: /http:/127.0.0.1:8000/status
>>> [12/Jul/2018 10:02:59] "GET
>>> http://127.0.0.1:8000/status?plain&encode=b64&set_os_username=RE1Dx&osid=1
>>> HTTP/1.1" 404 1768
>>> ...
>>> ...
>>>
>>> Could anyone tell me if it's a bug of Django, a missconfiguration or
>>> what?
>>>
>>> Running the server without ssh tunneling is OK. I had to add
>>> localhost.localdomain and 127.0.0.1 to allowed hosts in settings.py.
>>>
>>> Django version 2.0.6.
>>>
>>> Thank you in advance.
>>> Dikus
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "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/a42794fb-e9d8-4aa5-8e22-3180e4ef53eb%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/CAH9y-HygyFWSYymfoYQQC%2BkeOMJRq1uBPJ%2Ber3rboX8M1agREQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.