Re: Web based IDE for django

2016-08-17 Thread James Schneider
>
> New in django so here is the question: Is there a web based IDE for django
> where the environments are set up and all we focus on the creating models,
> view and control? It seems most of my time is spend creating url, import
> this, import that, put middleware, 90% of the time is spend worrying about
> the framework that actually doing the work. Its 2016 and its still seems
> like going back in time with the framework where everything is very manual
> driven.
>

It sounds like you desire a Content Management System (CMS) such as
Wordpress or Drupal, not a web framework such as Django. A CMS provides a
fair amount of the WYSIWYG features that you are inquiring about (click to
install plugin, configure everything via web forms, etc.). The drawback
there is that you are beholden to the decisions that the CMS developers
have made for you, which may or may not be suitable. Sure, you can override
behaviors and develop custom modules and plugins for a CMS, but then you
are down in the trenches doing very similar things to your CMS as you are
now with Django. I spent several years of my life developing a large custom
module for Drupal, and the primary reason I switched from Drupal to Django
is because, in the end, I spent more time overriding the decisions and
inadequacies of a CMS than moving the project forward. Not to mention the
bloat...

Django is a web framework, and is designed to be used at the "nuts and
bolts" level of web application development. Not website development, web
application development, notable difference. It is designed to allow the
developer to do things beyond uploading pictures and formatting text and
installing themes.

Probably every single developer on this list has a different philosophy and
setup, hence the reason that there are so many knobs to tweak in Django.
Projects like cookiecutter are great to set up an initial environment, but
again, the developers of cookiecutter (who are awesome IMHO) have a
particular philosophy about how things are set up, which is different even
from the "standard" layout that django-admin.py uses out of the box. Some
masochists probably have their entire project in a single file to keep
imports at a minimum.

Keep in mind that Django also readily accommodates the delineation between
the application programmer and web designer. Smaller projects likely have a
single person performing both tasks, but larger projects will spread the
work out.

I would say that spending 90% of your time on models, views, etc. is
actually a good thing. You need to make sure your data is handled properly
more than the site needs to look pretty (your customers may disagree).

My experience with Django is actually the opposite of yours (not by
choice), simply because I am a terrible web-designer and have spent
countless hours only to have my app look exactly like a Bootstrap example
page. It's a hobby project so it's not like I can/want to farm it out. It
is a bit annoying to have to string up a model, then a view, then a URL,
rinse, and repeat as necessary, but it's no different than having to
'create a page' in a CMS and figure out the URL title, etc. But then your
database becomes your configuration file, which means excessive queries.

Not sure how to take your "back in time" comment. Django supports all of
the current protocols and common protections that every other framework/CMS
does, probably more so. The only piece missing would be the
Channels/WebSockets integration, which is already in the works and is
currently available as a plugin.

I may also be completely misinterpreting what you are asking for. To answer
your question more directly, I've never seen a full-fledged online IDE (to
be fair, I haven't looked). Seems like there would be a fair amount of
custom integration needed with your hosting service for that to work, along
with your version control and publishing workflow. Not to mention
concurrent access issues, etc.

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


Non relational databases (MongoDB) with Django

2016-08-17 Thread Deep Shah
I want to use MongoDB with Django. Which are the advisable, latest and 
stable engines?
I found https://github.com/django-nonrel/mongodb-engine which requires the 
non relational version of Django 
(https://github.com/django-nonrel/django/). But they have not updated the 
code since Django 1.6.

-- 
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/f2a605c0-bcd9-45e9-8927-f9c8f09bc95b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Web based IDE for django

2016-08-17 Thread Joel Young
Check out Pycharm by Jetbrains.com (*I have no connection to the company)*.  
There is a free version that has less functionality.  The professional 
version is about $20/mo for the first year, then the price drops 
dramatically.  If you pay for a year at a time, the prices are: 
- $ 199.00 /1st year 
- $ 159.00 /2nd year
- $ 119.00 /3rd yr onwards
- I resisted paying for the professional version for a long time, but it 
makes development much easier and it's worth the investment.
- It has plugins and can setup a Django project for you quickly
- 

On Monday, August 15, 2016 at 4:48:44 PM UTC-4, billy...@gmail.com wrote:
>
> New in django so here is the question: Is there a web based IDE for django 
> where the environments are set up and all we focus on the creating models, 
> view and control? It seems most of my time is spend creating url, import 
> this, import that, put middleware, 90% of the time is spend worrying about 
> the framework that actually doing the work. Its 2016 and its still seems 
> like going back in time with the framework where everything is very manual 
> driven. 
>

-- 
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/4e9c74e1-7225-4374-a5d6-511a39605573%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Send mail after x hours

2016-08-17 Thread Kishan Mehta
Hi guys,

I am using django 1.9. I am working on requirement where we need to send
users reminder to activate their account by email after x hours h/she has
signed on our platform.

I have send_mail task and I have configured https://github.com/ui/django-rq to
send mails.

One way I can think of is to set up a cron job using
https://github.com/ui/rq-scheduler which runs every 5 mins to check for
users who signed up 6 hours before.

Is there any better way to do this ?

Thanks,
Kishan

-- 
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/CAC5ThKGOFyWObnZTV8VpT57eyWqEq5%2B-OaMj7L%3Dr%3Dh41bJVWXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django

2016-08-17 Thread 小柯
I think it's like answer 

??
Just create the dictionary like data = {'a': [ [1, 2] ], 'b': [ [3, 4] 
],'c':[ [5,6]] }
and then do get it from view

-- 
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/b7f2ec42-8c2a-4e4e-8118-f60de29c8823%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I build this ignore pattern for collectstatic?

2016-08-17 Thread 'voger' via Django users

Let's say somewhere inside my /static/ folder I have this tree

$ tree -L 2 -F --dirsfirst
.
├── qooxdoo -> ../../../qooxdoo//
└── qssite/
├── build/
├── source/
├── apache2.conf
├── config.json
├── config.json_orig
├── config.json_test
├── decode-source-uris.js
├── generate.py*
├── Gruntfile.js
├── Manifest.json
├── package.json
├── README.md
└── readme.txt

and let's say that I don't want collectstatic to collect anything except 
the folder qssite/build/


Is there any pattern I can use or should I list explicitly everything I 
want to be excluded?


Also what kind of patterns does it expect? Is it regular expression or 
something else?


--
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/d07055ec-0698-dae6-5525-1cfb780e04d3%40yahoo.gr.
For more options, visit https://groups.google.com/d/optout.


RE: Send mail after x hours

2016-08-17 Thread Dheerendra Rathor
I’ll suggest you to use some background task runner. Celery will work great for 
you as it is developed for Python and work on multiple platform with multiple 
types of message queues.

Sent from Mail for Windows 10

From: Kishan Mehta

-- 
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/57b4456d.4b50620a.2cdf7.e8fe%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.


Re: Send mail after x hours

2016-08-17 Thread Kishan Mehta
Thanks but I already have django rq adn rq-scheduler configured and running
so I was thinking to use it and avoid celery.


On Wed, Aug 17, 2016 at 4:37 PM, Dheerendra Rathor <
dheeru.ratho...@gmail.com> wrote:

> I’ll suggest you to use some background task runner. Celery will work
> great for you as it is developed for Python and work on multiple platform
> with multiple types of message queues.
>
>
>
> Sent from Mail  for
> Windows 10
>
>
>
> *From: *Kishan Mehta 
> *Sent: *Wednesday, August 17, 2016 4:35 PM
> *To: *django-users@googlegroups.com
> *Subject: *Send mail after x hours
>
>
>
> Hi guys,
>
>
>
> I am using django 1.9. I am working on requirement where we need to send
> users reminder to activate their account by email after x hours h/she has
> signed on our platform.
>
>
>
> I have send_mail task and I have configured https://github.com/
> ui/django-rq to send mails.
>
>
>
> One way I can think of is to set up a cron job using
> https://github.com/ui/rq-scheduler which runs every 5 mins to check for
> users who signed up 6 hours before.
>
>
>
> Is there any better way to do this ?
>
>
>
> Thanks,
>
> Kishan
>
> --
> 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/CAC5ThKGOFyWObnZTV8VpT57eyWqEq
> 5%2B-OaMj7L%3Dr%3Dh41bJVWXA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

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


Re: Non relational databases (MongoDB) with Django

2016-08-17 Thread Jani Tiainen

Hi,

Well you can use non relational databases with django. This of course 
means that you don't have ORM for that, use them as is. Way simpler than 
trying to force ORM (which stands for object relational mapper) to 
follow something non relational.


Also, if you're not stuck at mongodb, you may find arangodb much more 
appealing and doing most things "right".



On 17.08.2016 11:28, Deep Shah wrote:
I want to use MongoDB with Django. Which are the advisable, latest and 
stable engines?
I found https://github.com/django-nonrel/mongodb-engine which requires 
the non relational version of Django 
(https://github.com/django-nonrel/django/). But they have not updated 
the code since Django 1.6.

--
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/f2a605c0-bcd9-45e9-8927-f9c8f09bc95b%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
Jani Tiainen

--
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/911e1dd9-0be2-b369-2512-53e24cff67f5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


connecting to mssql database

2016-08-17 Thread sum abiut
Hi,
i am having a very hard time figuring out how to connect to a mssql
database. i've try following this guide but nothing seems to be working.
please help

http://www.tivix.com/blog/getting-django-working-with-mssql-pyodbc/

https://pypi.python.org/pypi/django-pyodbc-azure

cheers,

-- 
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/CAPCf-y5M37%2B9JRspvMEtUUOZVOp1SaUSuToGs0VdH%2B_DydPC8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: connecting to mssql database

2016-08-17 Thread Daniel França
What errors are you getting?

On Wed, 17 Aug 2016 at 14:15 sum abiut  wrote:

>
> Hi,
> i am having a very hard time figuring out how to connect to a mssql
> database. i've try following this guide but nothing seems to be working.
> please help
>
> http://www.tivix.com/blog/getting-django-working-with-mssql-pyodbc/
>
> https://pypi.python.org/pypi/django-pyodbc-azure
>
> cheers,
>
> --
> 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/CAPCf-y5M37%2B9JRspvMEtUUOZVOp1SaUSuToGs0VdH%2B_DydPC8A%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: How do I build this ignore pattern for collectstatic?

2016-08-17 Thread 'voger' via Django users
As to what kind of pattern it expects I found it. It expects glob style 
patterns like the shell prompt. Not much matching to be done here.



Still I am curious if there is any clever way to achieve this with 
pattern matching.



On 16/08/2016 11:30 μμ, 'voger' via Django users wrote:

Let's say somewhere inside my /static/ folder I have this tree

$ tree -L 2 -F --dirsfirst
.
├── qooxdoo -> ../../../qooxdoo//
└── qssite/
├── build/
├── source/
├── apache2.conf
├── config.json
├── config.json_orig
├── config.json_test
├── decode-source-uris.js
├── generate.py*
├── Gruntfile.js
├── Manifest.json
├── package.json
├── README.md
└── readme.txt

and let's say that I don't want collectstatic to collect anything except
the folder qssite/build/

Is there any pattern I can use or should I list explicitly everything I
want to be excluded?

Also what kind of patterns does it expect? Is it regular expression or
something else?



--
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/955d0427-51a2-4277-75b1-8088eeb2fc64%40yahoo.gr.
For more options, visit https://groups.google.com/d/optout.


Re: Non relational databases (MongoDB) with Django

2016-08-17 Thread Deep Shah
How easy is it to use MongoDb without a Django ORM once the code base 
increases?




On Wednesday, August 17, 2016 at 5:25:01 PM UTC+5:30, Jani Tiainen wrote:
>
> Hi,
>
> Well you can use non relational databases with django. This of course 
> means that you don't have ORM for that, use them as is. Way simpler than 
> trying to force ORM (which stands for object relational mapper) to follow 
> something non relational.
> Also, if you're not stuck at mongodb, you may find arangodb much more 
> appealing and doing most things "right".
>
>
> On 17.08.2016 11:28, Deep Shah wrote:
>
> I want to use MongoDB with Django. Which are the advisable, latest and 
> stable engines?
> I found https://github.com/django-nonrel/mongodb-engine which requires 
> the non relational version of Django (
> https://github.com/django-nonrel/django/). But they have not updated the 
> code since Django 1.6.
> -- 
> 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/f2a605c0-bcd9-45e9-8927-f9c8f09bc95b%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> -- 
> Jani Tiainen
>
>

-- 
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/92c41fc9-7a2d-4a59-b7ac-132450dd63ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with UpdateView and inline formset

2016-08-17 Thread flaudizio
Hi evebody,

I'm using formset with inline and I can create the object in CreateView, 
but in UpdateView I get this error:

Erro:

ValidationError at /cadastros/pacientes/atualizar/7/
["'' value must be integer."]

django/db/models/fields/__init__.py in to_python:

Variable  | value
self
value   ''

---

I think the ID (main form) don't are passing through inline.

---
My codings:
---

View:

http://pastebin.com/KPG8SJF5

Forms.py:

TelefonePessoaFormSet = inlineformset_factory(Paciente, TelefonePessoa, 
fields=('tipo', 'numero',), extra=2, can_delete=True)

Thank's for all.

-- 
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/5556c40b-63d5-4c9b-ac67-5edd327c0963%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Send mail after x hours

2016-08-17 Thread Asad Jibran Ahmed
Personally, I'd setup a simple cronjob on my machine that runs a Django 
management command. The command would get a list of users who are eligible 
to receive emails and send it to them.

I would have just used the send_mail directly from my management command, 
but if you already have a RQ setup for that, just go ahead and use the same.

This approach is simple and doesn't require using the rq-scheduler. But if 
you really want, using rq-scheduler is basically the same and the end 
result is similar.

On Wednesday, August 17, 2016 at 3:10:27 PM UTC+4, Kishan Mehta wrote:
>
> Thanks but I already have django rq adn rq-scheduler configured and 
> running so I was thinking to use it and avoid celery.
>
>
> On Wed, Aug 17, 2016 at 4:37 PM, Dheerendra Rathor  > wrote:
>
>> I’ll suggest you to use some background task runner. Celery will work 
>> great for you as it is developed for Python and work on multiple platform 
>> with multiple types of message queues.
>>
>>  
>>
>> Sent from Mail  for 
>> Windows 10
>>
>>  
>>
>> *From: *Kishan Mehta 
>> *Sent: *Wednesday, August 17, 2016 4:35 PM
>> *To: *django...@googlegroups.com 
>> *Subject: *Send mail after x hours
>>
>>  
>>
>> Hi guys,
>>
>>  
>>
>> I am using django 1.9. I am working on requirement where we need to send 
>> users reminder to activate their account by email after x hours h/she has 
>> signed on our platform.
>>
>>  
>>
>> I have send_mail task and I have configured 
>> https://github.com/ui/django-rq to send mails. 
>>
>>  
>>
>> One way I can think of is to set up a cron job using 
>> https://github.com/ui/rq-scheduler which runs every 5 mins to check for 
>> users who signed up 6 hours before. 
>>
>>  
>>
>> Is there any better way to do this ?
>>
>>  
>>
>> Thanks,
>>
>> Kishan
>>
>> -- 
>> 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/CAC5ThKGOFyWObnZTV8VpT57eyWqEq5%2B-OaMj7L%3Dr%3Dh41bJVWXA%40mail.gmail.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>  
>>
>
>

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


Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam
Hi,

I am a beginner and please forgive me if my question is not up to the 
standard. I've got two models one is Product which is saved in db already 
and another one is Shop. I am trying to related both models with following 
code.

class Product(models.Model):
user = models.ForeignKey(settings.USER_AUTH_MODEL)
title = models.CharField(max_length=120)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(decimal_places=2, max_digits=20)
publish_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
null=True, blank= True)
expire_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
null=True, blank=True)
active = models.BooleanField(default=True)
categories = models.ManyToManyField('Category', blank=True)
default = models.ForeignKey('Category', related_name='default_category', 
null=True, blank=True)
hitcounts = GenericRelation(HitCount, content_type_field='content_type', 
object_id_field='object_pk',)


objects = ProductManager()


class Meta:
ordering = ["-title"]


def __unicode__(self):
return self.title


class Shop(models.Model):
product = models.ManyToManyField(Product)

title = models.CharField(max_length=120, null=False)
image = models.ImageField(upload_to=image_upload_to_shop, null=True)
location = models.CharField(max_length=120)




def __unicode__(self):
return str(self.title)




With above I've got it added in my admin.py for Shop app and now I have a 
problem. When I add a shop it shows all the past products prepopulated in 
my "products" field. 
I just need to add the products that shop account holder has uploaded. I 
wish to use django\s built-in auth model to register shop holders. Again 
the confusion is that where should I add 
USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then for 
beginner like me it will be easy to use querysets. Please advise the best 
practice for above scenario.

-- 
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/bf649b76-0a5e-4e48-b54c-dfdcd0ae1a16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread ludovic coues
Do you have any error with the code you posted ?
It look like you already have a foreign key to your user.

2016-08-17 15:33 GMT+02:00 Shamaila Moazzam :
> Hi,
>
> I am a beginner and please forgive me if my question is not up to the
> standard. I've got two models one is Product which is saved in db already
> and another one is Shop. I am trying to related both models with following
> code.
>
> class Product(models.Model):
> user = models.ForeignKey(settings.USER_AUTH_MODEL)
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
> publish_date = models.DateTimeField(auto_now=False, auto_now_add=False,
> null=True, blank= True)
> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False,
> null=True, blank=True)
> active = models.BooleanField(default=True)
> categories = models.ManyToManyField('Category', blank=True)
> default = models.ForeignKey('Category', related_name='default_category',
> null=True, blank=True)
> hitcounts = GenericRelation(HitCount, content_type_field='content_type',
> object_id_field='object_pk',)
>
>
> objects = ProductManager()
>
>
> class Meta:
> ordering = ["-title"]
>
>
> def __unicode__(self):
> return self.title
>
>
> class Shop(models.Model):
> product = models.ManyToManyField(Product)
>
> title = models.CharField(max_length=120, null=False)
> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
> location = models.CharField(max_length=120)
>
>
>
>
> def __unicode__(self):
> return str(self.title)
>
>
>
>
> With above I've got it added in my admin.py for Shop app and now I have a
> problem. When I add a shop it shows all the past products prepopulated in my
> "products" field.
> I just need to add the products that shop account holder has uploaded. I
> wish to use django\s built-in auth model to register shop holders. Again the
> confusion is that where should I add
> USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then for
> beginner like me it will be easy to use querysets. Please advise the best
> practice for above scenario.
>
> --
> 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/bf649b76-0a5e-4e48-b54c-dfdcd0ae1a16%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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/CAEuG%2BTaAb_nooX2bzMT_mrnRLD--keYP9SM_v7BTLj6fdw_owg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Can't make Django ORM work for multiple models

2016-08-17 Thread Shamaila Moazzam
I am trying to create a parent model for my products app and I need to 
provide the user reference. I've registered the Shop model with admin.py. 
Now I have problem that when I see in model it shows all the products 
listed before. I only intend to show products added by the shop owner. Also 
I need to register shop using built-in auth system so how do I do that, 
should I add user field in Shop or in Product. To brief in detail following 
are my models. Thanks for your kind help and apologies if as beginner i've 
missed any information or if the question isn't up to standard.

shops/models.py:

class Shop(models.Model):
#shop_user = models.ForeignKey(settings.USER_AUTH_MODEL, blank=False, 
null=False)
product = models.ManyToManyField(Product, related_name='myshop',null=
False, blank=True)
Title = models.CharField(max_length=120, null=False)
image = models.ImageField(upload_to=image_upload_to_shop, null=True)
location = models.CharField(max_length=120)




def __unicode__(self):
return str(self.Title)


products/models.py:

class Product(models.Model):
#user = models.ForeignKey(settings.USER_AUTH_MODEL)
title = models.CharField(max_length=120)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(decimal_places=2, max_digits=20)
publish_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
null=True, blank= True)
expire_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
null=True, blank=True)
active = models.BooleanField(default=True)
categories = models.ManyToManyField('Category', blank=True)
default = models.ForeignKey('Category', related_name='default_category', 
null=True, blank=True)
hitcounts = GenericRelation(HitCount, content_type_field='content_type', 
object_id_field='object_pk',)


   def __unicode__(self): #def __str__(self):
return self.title


-- 
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/c31416eb-37a7-40b3-98ca-a04258f46330%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Non relational databases (MongoDB) with Django

2016-08-17 Thread Avraham Serour
Why do you need to use mongodb? Why not just use postgres and all the
tooling the django ORM provides?


On Wed, Aug 17, 2016 at 3:32 PM, Deep Shah  wrote:

> How easy is it to use MongoDb without a Django ORM once the code base
> increases?
>
>
>
>
> On Wednesday, August 17, 2016 at 5:25:01 PM UTC+5:30, Jani Tiainen wrote:
>>
>> Hi,
>>
>> Well you can use non relational databases with django. This of course
>> means that you don't have ORM for that, use them as is. Way simpler than
>> trying to force ORM (which stands for object relational mapper) to follow
>> something non relational.
>> Also, if you're not stuck at mongodb, you may find arangodb much more
>> appealing and doing most things "right".
>>
>>
>> On 17.08.2016 11:28, Deep Shah wrote:
>>
>> I want to use MongoDB with Django. Which are the advisable, latest and
>> stable engines?
>> I found https://github.com/django-nonrel/mongodb-engine which requires
>> the non relational version of Django (https://github.com/django-non
>> rel/django/). But they have not updated the code since Django 1.6.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/f2a605c0-bcd9-45e9-8927-f9c8f09bc95b%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> Jani Tiainen
>>
>> --
> 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/92c41fc9-7a2d-4a59-b7ac-132450dd63ef%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/CAFWa6t%2Bx3yx-V3oYC4%2BA3%3DeNqNDgmqh4MpCeUY9_GEmZ1DyHRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Subtracting UNIX_TIMESTAMPS broke in Django 1.10

2016-08-17 Thread Simon Charette
Hi Dan!

I'm the author of the temporal substraction changes in 1.10.

I believe the main culprit here is your usage of `Func` with no explicit
`output_field`. When this parameter is not specified the return type of 
`Func`
expressions is determined by it's wrapped expressions given there's either
only one or they are all of the same type[1].

In your case the `Func('start', function='UNIX_TIMESTAMP')` expression is
assumed to have a return type of `models.DateTimeField` as it's the data 
type of
the `TaskLog.start` field. It should have been declared with an 
`output_field`
of `models.IntegerField()` instead.

Let me know if that doesn't make sense to you.

Cheers,
Simon

[1] 
https://github.com/django/django/blob/19e20a2a3f763388bba9263d56db34012e90cf5b/django/db/models/expressions.py#L265-L270

P.-S. You should replace your `.extra()` usage with an `annotate()` call as
this API is meant to be deprecated:

TaskLog.objects.annotate(
day=Func('start', 10, function='LEFT', output_field=models.CharField()),
).values('day').annotate(sum=Sum(F('stop') - F('start')))

Le mardi 16 août 2016 13:48:37 UTC-4, Dan Edwards a écrit :
>
> I have a query that works in Django 1.9.9 but not 1.10. Running on CentOS 
> 7, with python 2.7.5, and MySQL 5.6.23 on Amazon RDS
> Example:
>
> class TaskLog(models.Model):
> id = models.AutoField(primary_key=True)
> start = models.DateTimeField(auto_now_add=True)
> stop = models.DateTimeField(blank=True, null=True, default=None) 
>
> Query =  TaskLog.objects.extra(select = {"day": "left(start, 
> 10)"}).values("day").annotate(sum=Sum(Func(F('stop'), 
> function='UNIX_TIMESTAMP') - Func(F('start'), function='UNIX_TIMESTAMP')))
>
> In 1.9.9 the value for sum would be the sum of the number of seconds 
> between start and stop. 
> In 1.10 it is always None.
>
> The sql generated is:
> Django 1.9.9:
> SELECT (left(start, 10)) AS `day`, SUM((UNIX_TIMESTAMP(`TaskLog`.`stop`) - 
> UNIX_TIMESTAMP(`TaskLog`.`start`))) AS `sum`  FROM `TaskLog` WHERE 
> (`TaskLog`.`user_id` = 22) GROUP BY UNIX_TIMESTAMP(`TaskLog`.`stop`), 
> UNIX_TIMESTAMP(`TaskLog`.`start`), (left(start, 10)) ORDER BY NULL
>
> Django 1.10:
> SELECT (left(start, 10)) AS `day`, SUM(TIMESTAMPDIFF(MICROSECOND, 
> UNIX_TIMESTAMP(`TaskLog`.`start`), UNIX_TIMESTAMP(`TaskLog`.`stop`))) AS 
> `sum` FROM `TaskLog` WHERE (`TaskLog`.`user_id` = 22) GROUP BY (left(start, 
> 10)) ORDER BY NULL
>
> It looks like the new temporal subtraction feature to swap out the - with 
> TIMESTAMPDIFF is the problem. Maybe it shouldn't do that for 
> UNIX_TIMESTAMPs?
>
> I fixed my app by simplifying my code to not convert to UNIX_TIMESTAMP 
> before subtracting:
> Query =  TaskLog.objects.extra(select = {"day": "left(start, 
> 10)"}).values("day").annotate(sum=Sum(F('stop') - F('start')))
>
> But thought I should still report that subtracting UNIX_TIMESTAMPs appears 
> to be broken
>

-- 
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/7db6868b-6b0f-47e4-8eed-b1567c3b3854%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to save one field value from a model to another model field

2016-08-17 Thread Vinicius Assef
Your method get_shift_date() has a syntax error.

Your save() method has identation problem.

Please correct them and send us the right code.



On Tuesday, 16 August 2016 14:49:32 UTC-3, Md. Ohiduzzaman wrote:
>
>
>
> down votefavorite 
> 
>
> I designed two models: one model for storing Sitting date and another mode 
> for storing Shifting date. Two model are linked by foreign key. Here is my 
> two models:
>
> class Sitting(models.Model):
> sit_date = models.DateField(blank=False,unique=True)
> cut_off_date = models.DateField(null=True, blank=True)
> ballot_date = models.DateField(null=True, blank=True)
> sess_no = models.ForeignKey(Session,
>  on_delete=models.CASCADE)
> genre = TreeForeignKey('Genre', null=True, blank=True, db_index=True)
>
> Shift Model:
>
>  class Shiftdate(models.Model):
> shift_date = models.DateField(blank=False,unique=True)
> sit_date = models.ForeignKey(Sitting,
> on_delete=models.CASCADE)
>
> Using Shift model's shift_date, I changed existing sitting dates to other 
> dates as:
>
> Sitting Date Shifting Date2016-09-01   Sept. 15, 20162016-09-08   
> Sept. 19, 2016
>
>
> Now I want to make these shift date to a new sitting dates.  For this I 
> define following method in Sitting model:
>
>
> def get_shift_date(self):
> return self.sit_date= self.shift_date 
>
>
> And this shift_date to be saved in the Sitting model in sit_date field. I 
> define following save method:
>
>  def save(self, *args, **kwargs):  
> self.sit_date = self.get_shift_date()
> super(Sitting, self).save(*args, **kwargs)
>
>
> But this did not return shift dates as sitting dates. Could someone help 
> me to fix this codes?
>
>

-- 
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/c18c34d2-e8af-43b9-bd39-644581cd790d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread M Hashmi
So what you are saying is that you don't need to get all the products
instead only products uploaded by a particular user?
This makes sense because you are getting the whole model called with the
key so if I am getting your question right you just need to apply some sort
of filter to get user related products. Which means by default first time
user gets registered it shouldn't show any products but same time if
product is added by the shop owner he should be able to see that.

Respond please.

On Wed, Aug 17, 2016 at 6:44 AM, ludovic coues  wrote:

> Do you have any error with the code you posted ?
> It look like you already have a foreign key to your user.
>
> 2016-08-17 15:33 GMT+02:00 Shamaila Moazzam :
> > Hi,
> >
> > I am a beginner and please forgive me if my question is not up to the
> > standard. I've got two models one is Product which is saved in db already
> > and another one is Shop. I am trying to related both models with
> following
> > code.
> >
> > class Product(models.Model):
> > user = models.ForeignKey(settings.USER_AUTH_MODEL)
> > title = models.CharField(max_length=120)
> > description = models.TextField(blank=True, null=True)
> > price = models.DecimalField(decimal_places=2, max_digits=20)
> > publish_date = models.DateTimeField(auto_now=False,
> auto_now_add=False,
> > null=True, blank= True)
> > expire_date = models.DateTimeField(auto_now=False,
> auto_now_add=False,
> > null=True, blank=True)
> > active = models.BooleanField(default=True)
> > categories = models.ManyToManyField('Category', blank=True)
> > default = models.ForeignKey('Category', related_name='default_
> category',
> > null=True, blank=True)
> > hitcounts = GenericRelation(HitCount, content_type_field='content_
> type',
> > object_id_field='object_pk',)
> >
> >
> > objects = ProductManager()
> >
> >
> > class Meta:
> > ordering = ["-title"]
> >
> >
> > def __unicode__(self):
> > return self.title
> >
> >
> > class Shop(models.Model):
> > product = models.ManyToManyField(Product)
> >
> > title = models.CharField(max_length=120, null=False)
> > image = models.ImageField(upload_to=image_upload_to_shop, null=True)
> > location = models.CharField(max_length=120)
> >
> >
> >
> >
> > def __unicode__(self):
> > return str(self.title)
> >
> >
> >
> >
> > With above I've got it added in my admin.py for Shop app and now I have a
> > problem. When I add a shop it shows all the past products prepopulated
> in my
> > "products" field.
> > I just need to add the products that shop account holder has uploaded. I
> > wish to use django\s built-in auth model to register shop holders. Again
> the
> > confusion is that where should I add
> > USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then
> for
> > beginner like me it will be easy to use querysets. Please advise the best
> > practice for above scenario.
> >
> > --
> > 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/bf649b76-
> 0a5e-4e48-b54c-dfdcd0ae1a16%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> 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/CAEuG%2BTaAb_nooX2bzMT_mrnRLD--
> keYP9SM_v7BTLj6fdw_owg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam

@Mudassar this is exactly what I need.




On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>
> Hi,
>
> I am a beginner and please forgive me if my question is not up to the 
> standard. I've got two models one is Product which is saved in db already 
> and another one is Shop. I am trying to related both models with following 
> code.
>
> class Product(models.Model):
> user = models.ForeignKey(settings.USER_AUTH_MODEL)
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
> publish_date = models.DateTimeField(auto_now=False, auto_now_add=False
> , null=True, blank= True)
> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
> null=True, blank=True)
> active = models.BooleanField(default=True)
> categories = models.ManyToManyField('Category', blank=True)
> default = models.ForeignKey('Category', related_name=
> 'default_category', null=True, blank=True)
> hitcounts = GenericRelation(HitCount, content_type_field=
> 'content_type', object_id_field='object_pk',)
>
>
> objects = ProductManager()
>
>
> class Meta:
> ordering = ["-title"]
>
>
> def __unicode__(self):
> return self.title
>
>
> class Shop(models.Model):
> product = models.ManyToManyField(Product)
>
> title = models.CharField(max_length=120, null=False)
> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
> location = models.CharField(max_length=120)
>
>
>
>
> def __unicode__(self):
> return str(self.title)
>
>
>
>
> With above I've got it added in my admin.py for Shop app and now I have a 
> problem. When I add a shop it shows all the past products prepopulated in 
> my "products" field. 
> I just need to add the products that shop account holder has uploaded. I 
> wish to use django\s built-in auth model to register shop holders. Again 
> the confusion is that where should I add 
> USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then 
> for beginner like me it will be easy to use querysets. Please advise the 
> best practice for above scenario.
>

-- 
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/10d630fa-7381-46c2-8d6b-35964b86dc09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't make Django ORM work for multiple models

2016-08-17 Thread Todor Velichkov

>
> I only intend to show products added by the shop owner.
>
 
You can do this by using the reverse m2m relation between product and shop.

products = Product.objects.filter(shop__shop_user=request.user)

However, I think it's more suitable for the product to keep the M2M 
relation, because naturally when you add a new product you would want to 
choose its shops. If a product can belong to only one shop, then you can 
even use a Foreign Key instead of M2M Field. 

Also I need to register shop using built-in auth system so how do I do that
>

I'm not sure what is the question here, you have access to request.user, 
just assign it to shop_user when you create a new shop. 

should I add user field in Shop or in Product.
>

It really depends on what you need, you already mention that you need a 
Shop.owner, so you can't go without user FK into Shop model. IF you think 
you are gonna need and a Product owner/creator as well, then you can add 
user FK to products as well. These things are not mutually exclusive.



On Wednesday, August 17, 2016 at 4:37:51 PM UTC+3, Shamaila Moazzam wrote:
>
> I am trying to create a parent model for my products app and I need to 
> provide the user reference. I've registered the Shop model with admin.py. 
> Now I have problem that when I see in model it shows all the products 
> listed before. I only intend to show products added by the shop owner. Also 
> I need to register shop using built-in auth system so how do I do that, 
> should I add user field in Shop or in Product. To brief in detail following 
> are my models. Thanks for your kind help and apologies if as beginner i've 
> missed any information or if the question isn't up to standard.
>
> shops/models.py:
>
> class Shop(models.Model):
> #shop_user = models.ForeignKey(settings.USER_AUTH_MODEL, blank=False, 
> null=False)
> product = models.ManyToManyField(Product, related_name='myshop',null=
> False, blank=True)
> Title = models.CharField(max_length=120, null=False)
> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
> location = models.CharField(max_length=120)
>
>
>
>
> def __unicode__(self):
> return str(self.Title)
>
>
> products/models.py:
>
> class Product(models.Model):
> #user = models.ForeignKey(settings.USER_AUTH_MODEL)
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
> publish_date = models.DateTimeField(auto_now=False, auto_now_add=False
> , null=True, blank= True)
> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
> null=True, blank=True)
> active = models.BooleanField(default=True)
> categories = models.ManyToManyField('Category', blank=True)
> default = models.ForeignKey('Category', related_name=
> 'default_category', null=True, blank=True)
> hitcounts = GenericRelation(HitCount, content_type_field=
> 'content_type', object_id_field='object_pk',)
>
>
>def __unicode__(self): #def __str__(self):
> return self.title
>
>
>

-- 
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/1a565b81-f173-43a9-aa6c-63f3b51193e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django

2016-08-17 Thread Wolf Painter
Thank you, I will have to look into this. Django is a bit confusing to me 
as I'm just learning it, so I'm not as versed as I could be about all the 
options. What I'm trying to accomplish is a list of the copies of base 
images on each server, not sure if that makes sense. But here is an example:

win2k12_excel is a base image that can live on many servers, a copy of this 
image would be 0012_win2k12_excel which would live on only one server. I 
need to know how many copies of this base image live on each server and 
display that so I can either increase or decrease the count on each server. 
Does that make sense? I'm not sure if making ChildImage a subclass is what 
I want because the number of copies on each server can and will change 
frequently, as will the number 0012 in the earlier example. On top of the 
number of copies changing, images can and will be retired, so they will 
eventually be deleted and servers will change as they need updating. 

I will look into aggregate to see if it will work for what I'm trying to 
accomplish. Thank you!

On Tuesday, August 16, 2016 at 11:00:09 PM UTC-7, Andrew Beales wrote:
>
> Hi, you can use aggregation queries to count the child images connected to 
> each server:
>
>
> # views.py
>
> from django.db.models import Count
>
> def servers(request):
> servers = Server.objects.all()
> for server in servers:
> server.child_images = server.images.aggregate(total=Count('base'))
> return render(request, "administration/servers.html", {'servers': 
> servers})
>
> # template
>
> {% for server in servers %}
>
>   Server: {{ server }}
>
>No. images: {{ server.images.count }}
>No. child images: {{ server.child_images.total }}
>
> {% endfor %}
>
> https://docs.djangoproject.com/en/1.10/topics/db/aggregation/
>
> ('child_image' would be a more suitable related_name than 'base')
>  
> Also, if server--image is a ManytoMany relation and an image can have many 
> child images, the ForeignKey relation here between Childimage and Server 
> would currently seem redundant/inaccurate. 
>
> More broadly, if all child images are types of images, you could consider 
> making ChildImage a subclass of Image instead, ie. class ChildImage(Image): 
> which might help with querying, as then you could just count child images 
> with server.childimage_set.count(), (if you removed the current 
> related_name for Childimage.server).
>
>
> On Tuesday, August 16, 2016 at 1:22:28 AM UTC+1, Wolf Painter wrote:
>>
>> Hey everyone, I didn't see any posts (or google search) that could 
>> possibly answer my question, so I am here... I'm trying to create a way to 
>> launch vm's on a Xen or VMWare server using a website. I have the python 
>> file written on the Server and am currently creating a DJango app to manage 
>> everything. I'm stuck in a big way. I  currently have models that track 
>> servers, images and child images launched from the parent, but I can't 
>> figure out how to display it properly in a template so i can update the 
>> count (either add or subtract a number of VM's from a server). I'm new to 
>> both Django and Python, so please excuse any ignorance here... Here are my 
>> relevant models:
>>
>> class Image(models.Model):
>> name = models.CharField(verbose_name='Image Name', max_length=50)
>> labID = models.ManyToManyField(Lab, blank=True, related_name='labID')
>> type = models.CharField(max_length=50)
>>
>> def __str__(self):
>> return self.name
>>
>>
>> class Server(models.Model):
>> name = models.CharField(verbose_name='Server Name', max_length=50)
>> ipAddress = models.CharField(max_length=15)
>> maxCCU = models.IntegerField(default=0)
>> images = models.ManyToManyField(Image, blank=True, 
>> related_name='baseImage')
>>
>> def __str__(self):
>> return self.ipAddress
>>
>> class Childimage(models.Model):
>> name = models.CharField(verbose_name='Child Image Name', max_length=50)
>> parent = models.ForeignKey(Image, related_name='base')
>> server = models.ForeignKey(Server, related_name='server')
>> inUse = models.BooleanField()
>> rdpportnum = models.CharField(max_length=4)
>>
>> def __str__(self):
>> return self.name
>>
>> What I'm trying to do is have a web page that displays the number of parent 
>> images on a server by counting the child image. For example, I have a parent 
>> image called win2k12_excel and there are 12 child images of the parent 
>> win2k12_excel on the x.x.x.x server. I would like a web page that shows 
>> there are 12 win2k12_excel images on that server that would allow me to add 
>> or subtract the number on that server.
>>
>>
>> I have created a view that does this and puts it into a multidimensional 
>> dictionary, but I cannot figure out how to get that to render properly in a 
>> template. Here is my view:
>>
>>
>> def servers(request):
>> serverlist = Server.objects.all()
>> imagelist = Image.objects.filter(baseImage__in=server

Re: Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam
@Ludovic there is no error. Just I don't want to get all the products 
pre-populated. I need empty products field and only when user uploads 
products then it should show me products. Please advise

On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>
> Hi,
>
> I am a beginner and please forgive me if my question is not up to the 
> standard. I've got two models one is Product which is saved in db already 
> and another one is Shop. I am trying to related both models with following 
> code.
>
> class Product(models.Model):
> user = models.ForeignKey(settings.USER_AUTH_MODEL)
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
> publish_date = models.DateTimeField(auto_now=False, auto_now_add=False
> , null=True, blank= True)
> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
> null=True, blank=True)
> active = models.BooleanField(default=True)
> categories = models.ManyToManyField('Category', blank=True)
> default = models.ForeignKey('Category', related_name=
> 'default_category', null=True, blank=True)
> hitcounts = GenericRelation(HitCount, content_type_field=
> 'content_type', object_id_field='object_pk',)
>
>
> objects = ProductManager()
>
>
> class Meta:
> ordering = ["-title"]
>
>
> def __unicode__(self):
> return self.title
>
>
> class Shop(models.Model):
> product = models.ManyToManyField(Product)
>
> title = models.CharField(max_length=120, null=False)
> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
> location = models.CharField(max_length=120)
>
>
>
>
> def __unicode__(self):
> return str(self.title)
>
>
>
>
> With above I've got it added in my admin.py for Shop app and now I have a 
> problem. When I add a shop it shows all the past products prepopulated in 
> my "products" field. 
> I just need to add the products that shop account holder has uploaded. I 
> wish to use django\s built-in auth model to register shop holders. Again 
> the confusion is that where should I add 
> USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then 
> for beginner like me it will be easy to use querysets. Please advise the 
> best practice for above scenario.
>

-- 
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/7e4ba681-de3c-4cda-9940-3312987e9c06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't make Django ORM work for multiple models

2016-08-17 Thread Shamaila Moazzam
Thanks for reply Todor, But how to fix it in admin.py?

On Wednesday, August 17, 2016 at 7:52:20 PM UTC+5, Todor Velichkov wrote:
>
> I only intend to show products added by the shop owner.
>>
>  
> You can do this by using the reverse m2m relation between product and shop.
>
> products = Product.objects.filter(shop__shop_user=request.user)
>
> However, I think it's more suitable for the product to keep the M2M 
> relation, because naturally when you add a new product you would want to 
> choose its shops. If a product can belong to only one shop, then you can 
> even use a Foreign Key instead of M2M Field. 
>
> Also I need to register shop using built-in auth system so how do I do that
>>
>
> I'm not sure what is the question here, you have access to request.user, 
> just assign it to shop_user when you create a new shop. 
>
> should I add user field in Shop or in Product.
>>
>
> It really depends on what you need, you already mention that you need a 
> Shop.owner, so you can't go without user FK into Shop model. IF you think 
> you are gonna need and a Product owner/creator as well, then you can add 
> user FK to products as well. These things are not mutually exclusive.
>
>
>
> On Wednesday, August 17, 2016 at 4:37:51 PM UTC+3, Shamaila Moazzam wrote:
>>
>> I am trying to create a parent model for my products app and I need to 
>> provide the user reference. I've registered the Shop model with admin.py. 
>> Now I have problem that when I see in model it shows all the products 
>> listed before. I only intend to show products added by the shop owner. Also 
>> I need to register shop using built-in auth system so how do I do that, 
>> should I add user field in Shop or in Product. To brief in detail following 
>> are my models. Thanks for your kind help and apologies if as beginner i've 
>> missed any information or if the question isn't up to standard.
>>
>> shops/models.py:
>>
>> class Shop(models.Model):
>> #shop_user = models.ForeignKey(settings.USER_AUTH_MODEL, 
>> blank=False, null=False)
>> product = models.ManyToManyField(Product, related_name='myshop',null=
>> False, blank=True)
>> Title = models.CharField(max_length=120, null=False)
>> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
>> location = models.CharField(max_length=120)
>>
>>
>>
>>
>> def __unicode__(self):
>> return str(self.Title)
>>
>>
>> products/models.py:
>>
>> class Product(models.Model):
>> #user = models.ForeignKey(settings.USER_AUTH_MODEL)
>> title = models.CharField(max_length=120)
>> description = models.TextField(blank=True, null=True)
>> price = models.DecimalField(decimal_places=2, max_digits=20)
>> publish_date = models.DateTimeField(auto_now=False, auto_now_add=
>> False, null=True, blank= True)
>> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False
>> , null=True, blank=True)
>> active = models.BooleanField(default=True)
>> categories = models.ManyToManyField('Category', blank=True)
>> default = models.ForeignKey('Category', related_name=
>> 'default_category', null=True, blank=True)
>> hitcounts = GenericRelation(HitCount, content_type_field=
>> 'content_type', object_id_field='object_pk',)
>>
>>
>>def __unicode__(self): #def __str__(self):
>> return self.title
>>
>>
>>

-- 
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/a5d1e310-47f3-4cb1-aa5b-47a294337ec5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread ludovic coues
Could you share your admin.py file ?

You might be interested into this part of the documentation:
https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey

2016-08-17 17:20 GMT+02:00 Shamaila Moazzam :
> @Ludovic there is no error. Just I don't want to get all the products
> pre-populated. I need empty products field and only when user uploads
> products then it should show me products. Please advise
>
> On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>>
>> Hi,
>>
>> I am a beginner and please forgive me if my question is not up to the
>> standard. I've got two models one is Product which is saved in db already
>> and another one is Shop. I am trying to related both models with following
>> code.
>>
>> class Product(models.Model):
>> user = models.ForeignKey(settings.USER_AUTH_MODEL)
>> title = models.CharField(max_length=120)
>> description = models.TextField(blank=True, null=True)
>> price = models.DecimalField(decimal_places=2, max_digits=20)
>> publish_date = models.DateTimeField(auto_now=False,
>> auto_now_add=False, null=True, blank= True)
>> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False,
>> null=True, blank=True)
>> active = models.BooleanField(default=True)
>> categories = models.ManyToManyField('Category', blank=True)
>> default = models.ForeignKey('Category',
>> related_name='default_category', null=True, blank=True)
>> hitcounts = GenericRelation(HitCount,
>> content_type_field='content_type', object_id_field='object_pk',)
>>
>>
>> objects = ProductManager()
>>
>>
>> class Meta:
>> ordering = ["-title"]
>>
>>
>> def __unicode__(self):
>> return self.title
>>
>>
>> class Shop(models.Model):
>> product = models.ManyToManyField(Product)
>>
>> title = models.CharField(max_length=120, null=False)
>> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
>> location = models.CharField(max_length=120)
>>
>>
>>
>>
>> def __unicode__(self):
>> return str(self.title)
>>
>>
>>
>>
>> With above I've got it added in my admin.py for Shop app and now I have a
>> problem. When I add a shop it shows all the past products prepopulated in my
>> "products" field.
>> I just need to add the products that shop account holder has uploaded. I
>> wish to use django\s built-in auth model to register shop holders. Again the
>> confusion is that where should I add
>> USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then
>> for beginner like me it will be easy to use querysets. Please advise the
>> best practice for above scenario.
>
> --
> 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/7e4ba681-de3c-4cda-9940-3312987e9c06%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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/CAEuG%2BTaLojgozZM-rCmJ6BKo2o1r1%3D%2BinFVjaidsNRZ-CeMb2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't make Django ORM work for multiple models

2016-08-17 Thread Shamaila Moazzam
shops/admin.py

from .models import Shop

admin.site.register(Shop)



products/admin.py


from .models import Product, Variation, ProductImage, Category, 
ProductFeatured, color_product, size_product



class ProductImageInline(admin.TabularInline):
model = ProductImage
extra = 0
max_num = 10

class VariationInline(admin.TabularInline):
model = Variation
extra = 0
max_num = 10


class ProductAdmin(admin.ModelAdmin):
list_display = ['__unicode__', 'price',]
inlines = [
ProductImageInline,
VariationInline,


]
class Meta:
model = Product


admin.site.register(Product, ProductAdmin)




#admin.site.register(Variation)

admin.site.register(ProductImage)


admin.site.register(Category)


admin.site.register(ProductFeatured)

admin.site.register(color_product)

admin.site.register(size_product)



Thanks for reply Todor, But how to fix it in admin.py?

On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>
> I am trying to create a parent model for my products app and I need to 
> provide the user reference. I've registered the Shop model with admin.py. 
> Now I have problem that when I see in model it shows all the products 
> listed before. I only intend to show products added by the shop owner. Also 
> I need to register shop using built-in auth system so how do I do that, 
> should I add user field in Shop or in Product. To brief in detail following 
> are my models. Thanks for your kind help and apologies if as beginner i've 
> missed any information or if the question isn't up to standard.
>
> shops/models.py:
>
> class Shop(models.Model):
> #shop_user = models.ForeignKey(settings.USER_AUTH_MODEL, blank=False, 
> null=False)
> product = models.ManyToManyField(Product, related_name='myshop',null=
> False, blank=True)
> Title = models.CharField(max_length=120, null=False)
> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
> location = models.CharField(max_length=120)
>
>
>
>
> def __unicode__(self):
> return str(self.Title)
>
>
> products/models.py:
>
> class Product(models.Model):
> #user = models.ForeignKey(settings.USER_AUTH_MODEL)
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
> publish_date = models.DateTimeField(auto_now=False, auto_now_add=False
> , null=True, blank= True)
> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
> null=True, blank=True)
> active = models.BooleanField(default=True)
> categories = models.ManyToManyField('Category', blank=True)
> default = models.ForeignKey('Category', related_name=
> 'default_category', null=True, blank=True)
> hitcounts = GenericRelation(HitCount, content_type_field=
> 'content_type', object_id_field='object_pk',)
>
>
>def __unicode__(self): #def __str__(self):
> return self.title
>
>
>

-- 
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/e55d8864-bdd7-4b4a-ad70-7a3eadfa0dd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam


On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>
> Hi,
>
> I am a beginner and please forgive me if my question is not up to the 
> standard. I've got two models one is Product which is saved in db already 
> and another one is Shop. I am trying to related both models with following 
> code.
>
> class Product(models.Model):
> user = models.ForeignKey(settings.USER_AUTH_MODEL)
> title = models.CharField(max_length=120)
> description = models.TextField(blank=True, null=True)
> price = models.DecimalField(decimal_places=2, max_digits=20)
> publish_date = models.DateTimeField(auto_now=False, auto_now_add=False
> , null=True, blank= True)
> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False, 
> null=True, blank=True)
> active = models.BooleanField(default=True)
> categories = models.ManyToManyField('Category', blank=True)
> default = models.ForeignKey('Category', related_name=
> 'default_category', null=True, blank=True)
> hitcounts = GenericRelation(HitCount, content_type_field=
> 'content_type', object_id_field='object_pk',)
>
>
> objects = ProductManager()
>
>
> class Meta:
> ordering = ["-title"]
>
>
> def __unicode__(self):
> return self.title
>
>
> class Shop(models.Model):
> product = models.ManyToManyField(Product)
>
> title = models.CharField(max_length=120, null=False)
> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
> location = models.CharField(max_length=120)
>
>
>
>
> def __unicode__(self):
> return str(self.title)
>
>
>
>
> With above I've got it added in my admin.py for Shop app and now I have a 
> problem. When I add a shop it shows all the past products prepopulated in 
> my "products" field. 
> I just need to add the products that shop account holder has uploaded. I 
> wish to use django\s built-in auth model to register shop holders. Again 
> the confusion is that where should I add 
> USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then 
> for beginner like me it will be easy to use querysets. Please advise the 
> best practice for above scenario.
>

-- 
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/4f66b14f-6f23-4cac-a4cd-16be07454039%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread Shamaila Moazzam

shops/admin.py
from .models import Shop

admin.site.register(Shop)


products/admin.py


from .models import Product, Variation, ProductImage, Category, 
ProductFeatured, color_product, size_product



class ProductImageInline(admin.TabularInline):
model = ProductImage
extra = 0
max_num = 10

class VariationInline(admin.TabularInline):
model = Variation
extra = 0
max_num = 10


class ProductAdmin(admin.ModelAdmin):
list_display = ['__unicode__', 'price',]
inlines = [
ProductImageInline,
VariationInline,


]
class Meta:
model = Product


admin.site.register(Product, ProductAdmin)




#admin.site.register(Variation)

admin.site.register(ProductImage)


admin.site.register(Category)


admin.site.register(ProductFeatured)

admin.site.register(color_product)

admin.site.register(size_product)

On Wednesday, August 17, 2016 at 9:23:31 PM UTC+5, ludovic coues wrote:
>
> Could you share your admin.py file ? 
>
> You might be interested into this part of the documentation: 
>
> https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey
>  
>
> 2016-08-17 17:20 GMT+02:00 Shamaila Moazzam  >: 
> > @Ludovic there is no error. Just I don't want to get all the products 
> > pre-populated. I need empty products field and only when user uploads 
> > products then it should show me products. Please advise 
> > 
> > On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam 
> wrote: 
> >> 
> >> Hi, 
> >> 
> >> I am a beginner and please forgive me if my question is not up to the 
> >> standard. I've got two models one is Product which is saved in db 
> already 
> >> and another one is Shop. I am trying to related both models with 
> following 
> >> code. 
> >> 
> >> class Product(models.Model): 
> >> user = models.ForeignKey(settings.USER_AUTH_MODEL) 
> >> title = models.CharField(max_length=120) 
> >> description = models.TextField(blank=True, null=True) 
> >> price = models.DecimalField(decimal_places=2, max_digits=20) 
> >> publish_date = models.DateTimeField(auto_now=False, 
> >> auto_now_add=False, null=True, blank= True) 
> >> expire_date = models.DateTimeField(auto_now=False, 
> auto_now_add=False, 
> >> null=True, blank=True) 
> >> active = models.BooleanField(default=True) 
> >> categories = models.ManyToManyField('Category', blank=True) 
> >> default = models.ForeignKey('Category', 
> >> related_name='default_category', null=True, blank=True) 
> >> hitcounts = GenericRelation(HitCount, 
> >> content_type_field='content_type', object_id_field='object_pk',) 
> >> 
> >> 
> >> objects = ProductManager() 
> >> 
> >> 
> >> class Meta: 
> >> ordering = ["-title"] 
> >> 
> >> 
> >> def __unicode__(self): 
> >> return self.title 
> >> 
> >> 
> >> class Shop(models.Model): 
> >> product = models.ManyToManyField(Product) 
> >> 
> >> title = models.CharField(max_length=120, null=False) 
> >> image = models.ImageField(upload_to=image_upload_to_shop, 
> null=True) 
> >> location = models.CharField(max_length=120) 
> >> 
> >> 
> >> 
> >> 
> >> def __unicode__(self): 
> >> return str(self.title) 
> >> 
> >> 
> >> 
> >> 
> >> With above I've got it added in my admin.py for Shop app and now I have 
> a 
> >> problem. When I add a shop it shows all the past products prepopulated 
> in my 
> >> "products" field. 
> >> I just need to add the products that shop account holder has uploaded. 
> I 
> >> wish to use django\s built-in auth model to register shop holders. 
> Again the 
> >> confusion is that where should I add 
> >> USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then 
> >> for beginner like me it will be easy to use querysets. Please advise 
> the 
> >> best practice for above scenario. 
> > 
> > -- 
> > 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/7e4ba681-de3c-4cda-9940-3312987e9c06%40googlegroups.com.
>  
>
> > 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/4470ec74-21bf-48f5-8496-7b4c181

Python dictionaries saved to models

2016-08-17 Thread Aaron Weisberg
Hi everyone,

I have several dictionaries that I would like to import into my django 
project database, but I can't figure out exactly how.

I have tried to implement through fixtures, through views and through 
loaddata, but I must be doing something wrong at every turn- so if someone 
could suggest a workflow, it would really help me a lot!

My data is currently in a list of dictionaries called data:

Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 
'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 'university', 
'number': 10, 'exp': 1},


each dictionary within that list is a "player" who I'd like to input his 
data into my model "Players"

Enter code here...
#models.py
class Player(models.Model):

number = models.CharField(max_length=2)
player = models.CharField(max_length=50)
position = models.CharField(max_length=2)
height = models.CharField(max_length=50)
weight = models.CharField(max_length=50)
birth = models.DateField()
exp = models.CharField(max_length=50)
college = models.CharField(max_length=50)
def __str__(self):
return self.player


There are about 500 players in that list of dictionaries above that I would 
like to insert into this model.

1) Can i run a function in the model above to insert the data into its 
appropriate field?  If so, how do I execute that function?
2) If it's a view that I need to execute-  do I just put the function in 
views.py?  How then is the dictionary imported into the database?

or... How would you go about getting that data into your database?  Please 
note that the data is coming from a url that might change from time to 
time.  But I think once i get the first iteration of data into these models 
I can figure out how to update.  But the only way I can figure out is to 
create them one by one in the shell or create a form and input them one by 
one.

If you have a solution, please share and be as detailed as possible since I 
am a complete beginner with django.

Peace and love,

Aaron

-- 
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/83fa4e0a-c2b7-4c11-a78e-bd58c5df18b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Database data caching in Django?...

2016-08-17 Thread Fred Stluka

  
  
Django users,

Is there an easy way to enable an automatic write-through 
database cache in Django?

I'd want memcached or something to cache all data read by the 
Django ORM and use the cached copy on future reads, and of 
course update the cache as well as the DB (a "write-through" 
cache) when writing data.

Is there a piece of middleware I can activate to cause the ORM
to do this automatically for all DB queries?  Thanks!

Details:

I'm interested in caching the results of queries to the DB, not 
caching the results of templates or views.  So, it is different 
from the following, which I already know how to do:
- Caching of template files:
   -
http://us5.campaign-archive1.com/?u=a8d4be66d1927077a9255182d&id=a6f7d644a7&e=c90970e145
   -
https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
- Caching of all Django views for an entire site:
   -
https://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache
- Caching of specific Django views:
  -
https://docs.djangoproject.com/en/dev/topics/cache/#the-per-view-cache
- Caching of fragments of a Django Template:
  -
https://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching

I'm also hoping to not have to add cache API calls throughout my
code, as described here:
-
https://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-cache-api

I'd like the Django ORM to make the API calls for me automatically
when I call objects.get(), objects.filter(), save(), etc.  I'd hoped
to 
enable it simply by adding middleware or a custom manager or 
something.

Any suggestions?  I feel like I may be missing something obvious.

--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

  




-- 
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/054667d7-381c-9783-a959-626d72574537%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to save one field value from a model to another field of a linked model.

2016-08-17 Thread Fred Stluka

  
  
Md. Ohiduzzaman,

Looks good so far.  What happens when you try it?

--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

On 8/16/16 1:34 PM, Md. Ohiduzzaman
  wrote:


  I have designed a linked model named Shiftdate as:

  class Shiftdate(models.Model):
shift_date = models.DateField(blank=False,unique=True)
sit_date = models.ForeignKey(Sitting,
on_delete=models.CASCADE)Using this model I changed sit_date to shift_date which is like: Sitting Date Shifting Date
2016-09-01   Sept. 15, 2016
2016-09-08   Sept. 19, 2016
Now I need to save this shifting date to the Sitting date as sit_date in Sitting model. My Sitting model is:class Sitting(models.Model):
sit_date = models.DateField(blank=False,unique=True)
cut_off_date = models.DateField(null=True, blank=True)
ballot_date = models.DateField(null=True, blank=True)
sess_no = models.ForeignKey(Session,
 on_delete=models.CASCADE)
genre = TreeForeignKey('Genre', null=True, blank=True, db_index=True)
I use def get_shift_date(self):return self.sit_date=self.shift_date 

  
  -- 
  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/8894d393-5d97-4c97-ba56-1a319d93acec%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/c32af6d2-4ab6-73c5-8934-e08b4a3ff0a9%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't make Django ORM work for multiple models

2016-08-17 Thread Todor Velichkov
I don't know how much you are into Django, but in case you didn't you 
really need to ready carefully the following articles from the docs.

- Working with forms 
- Creating forms from models 

- The Django admin site 


there is more but this is just to get started. 

now after this, you should understand that in order to achieve what you 
want, you could do something like this:

class ProductAdmin(admin.ModelAdmin):
#...
exclude = ('shop_user',)

def save_model(self, request, obj, form, change):
if not change:
#set user on create only
obj.shop_user = request.user
obj.save()



On Wednesday, August 17, 2016 at 8:11:23 PM UTC+3, Shamaila Moazzam wrote:
>
> shops/admin.py
>
> from .models import Shop
>
> admin.site.register(Shop)
>
>
>
> products/admin.py
>
>
> from .models import Product, Variation, ProductImage, Category, 
> ProductFeatured, color_product, size_product
>
>
>
> class ProductImageInline(admin.TabularInline):
> model = ProductImage
> extra = 0
> max_num = 10
>
> class VariationInline(admin.TabularInline):
> model = Variation
> extra = 0
> max_num = 10
>
>
> class ProductAdmin(admin.ModelAdmin):
> list_display = ['__unicode__', 'price',]
> inlines = [
> ProductImageInline,
> VariationInline,
>
>
> ]
> class Meta:
> model = Product
>
>
> admin.site.register(Product, ProductAdmin)
>
>
>
>
> #admin.site.register(Variation)
>
> admin.site.register(ProductImage)
>
>
> admin.site.register(Category)
>
>
> admin.site.register(ProductFeatured)
>
> admin.site.register(color_product)
>
> admin.site.register(size_product)
>
>
>
> Thanks for reply Todor, But how to fix it in admin.py?
>
> On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam wrote:
>>
>> I am trying to create a parent model for my products app and I need to 
>> provide the user reference. I've registered the Shop model with admin.py. 
>> Now I have problem that when I see in model it shows all the products 
>> listed before. I only intend to show products added by the shop owner. Also 
>> I need to register shop using built-in auth system so how do I do that, 
>> should I add user field in Shop or in Product. To brief in detail following 
>> are my models. Thanks for your kind help and apologies if as beginner i've 
>> missed any information or if the question isn't up to standard.
>>
>> shops/models.py:
>>
>> class Shop(models.Model):
>> #shop_user = models.ForeignKey(settings.USER_AUTH_MODEL, 
>> blank=False, null=False)
>> product = models.ManyToManyField(Product, related_name='myshop',null=
>> False, blank=True)
>> Title = models.CharField(max_length=120, null=False)
>> image = models.ImageField(upload_to=image_upload_to_shop, null=True)
>> location = models.CharField(max_length=120)
>>
>>
>>
>>
>> def __unicode__(self):
>> return str(self.Title)
>>
>>
>> products/models.py:
>>
>> class Product(models.Model):
>> #user = models.ForeignKey(settings.USER_AUTH_MODEL)
>> title = models.CharField(max_length=120)
>> description = models.TextField(blank=True, null=True)
>> price = models.DecimalField(decimal_places=2, max_digits=20)
>> publish_date = models.DateTimeField(auto_now=False, auto_now_add=
>> False, null=True, blank= True)
>> expire_date = models.DateTimeField(auto_now=False, auto_now_add=False
>> , null=True, blank=True)
>> active = models.BooleanField(default=True)
>> categories = models.ManyToManyField('Category', blank=True)
>> default = models.ForeignKey('Category', related_name=
>> 'default_category', null=True, blank=True)
>> hitcounts = GenericRelation(HitCount, content_type_field=
>> 'content_type', object_id_field='object_pk',)
>>
>>
>>def __unicode__(self): #def __str__(self):
>> return self.title
>>
>>
>>

-- 
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/269459ce-f0bf-4850-8fad-c91f30f181a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unable to get tests to work

2016-08-17 Thread Matt
When I'm trying to get tests to work it simply states that its unable to 
import .tests. I'm not sure what I'm missing here. Here is some output 
please let me know if you need more:

./manage.py tests backups
https://dpaste.de/4U9C

The test file:
https://dpaste.de/bBZt

-- 
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/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-17 Thread Fred Stluka

  
  
Matt,

Drop the "s" from "tests":

./manage.py test backups

--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

On 8/17/16 4:17 PM, Matt wrote:


  When I'm trying to get tests to work it simply
states that its unable to import .tests. I'm not sure
what I'm missing here. Here is some output please let me know if
you need more:


./manage.py tests backups
https://dpaste.de/4U9C



The test file:
https://dpaste.de/bBZt

  
  -- 
  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/89d6fac7-0848-4e35-8b4a-62d24178c3aa%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/d6df2c33-01fc-ae4f-d9f9-4fb6296f5342%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-17 Thread Matt
Sorry for the typo, but I have already do that way. I have the output in 
the the first link.

On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote:
>
> Matt,
>
> Drop the "s" from "tests":
>
> ./manage.py test backups
>
> --Fred 
> --
> Fred Stluka -- mailt...@bristle.com  -- 
> http://bristle.com/~fred/ 
> Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
> Open Source: Without walls and fences, we need no Windows or Gates. 
> --
>
> On 8/17/16 4:17 PM, Matt wrote:
>
> When I'm trying to get tests to work it simply states that its unable to 
> import .tests. I'm not sure what I'm missing here. Here is some output 
> please let me know if you need more: 
>
> ./manage.py tests backups
> https://dpaste.de/4U9C
>
> The test file:
> https://dpaste.de/bBZt
> -- 
> 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/89d6fac7-0848-4e35-8b4a-62d24178c3aa%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/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-17 Thread Fred Stluka

  
  
Matt,

Oops!  Right.  I just noticed that in the dpaste.

My next guess is you may need to change the name

"good_index_text"
to something that starts with "test_" to get it to be recognized as
a 
test.

Or maybe something to do with "refreshes"?  The test trace shows
it trying to run testcase "refreshes.backups.tests", but in the
manual
import you did from the python shell, you only import
"backups.tests"

--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

On 8/17/16 4:27 PM, Matt wrote:


  Sorry for the typo, but I have already do that way.
I have the output in the the first link.

On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka
wrote:

   Matt,

Drop the "s" from "tests":

./manage.py test backups

--Fred 
   Fred Stluka -- mailt...@bristle.com
  -- http://bristle.com/~fred/ 
  Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
  
  Open Source: Without walls and fences, we need no Windows
  or Gates.
   

On 8/17/16 4:17 PM, Matt wrote:


  When I'm trying to get tests to work it
simply states that its unable to import
.tests. I'm not sure what I'm missing here.
Here is some output please let me know if you need more:


./manage.py tests backups
https://dpaste.de/4U9C



The test file:
https://dpaste.de/bBZt

  
  -- 
  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/89d6fac7-0848-4e35-8b4a-62d24178c3aa%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/04fcacea-15d0-42af-afe5-424c2d1df86f%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/fe478f0c-532e-8ad4-9b66-2a8145677f86%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: Database data caching in Django?...

2016-08-17 Thread Tim Graham
I did a quick search and found 
https://github.com/BertrandBordage/django-cachalot. Does it meet your 
requirements?

On Wednesday, August 17, 2016 at 3:34:33 PM UTC-4, Fred Stluka wrote:
>
> Django users,
>
> Is there an easy way to enable an automatic write-through 
> database cache in Django?
>
> I'd want memcached or something to cache all data read by the 
> Django ORM and use the cached copy on future reads, and of 
> course update the cache as well as the DB (a "write-through" 
> cache) when writing data.
>
> Is there a piece of middleware I can activate to cause the ORM
> to do this automatically for all DB queries?  Thanks!
>
> Details:
>
> I'm interested in caching the results of queries to the DB, not 
> caching the results of templates or views.  So, it is different 
> from the following, which I already know how to do:
> - Caching of template files:
>- 
> http://us5.campaign-archive1.com/?u=a8d4be66d1927077a9255182d&id=a6f7d644a7&e=c90970e145
>- 
> https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
> - Caching of all Django views for an entire site:
>- 
> https://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache
> - Caching of specific Django views:
>   - https://docs.djangoproject.com/en/dev/topics/cache/#the-per-view-cache
> - Caching of fragments of a Django Template:
>   - 
> https://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching
>
> I'm also hoping to not have to add cache API calls throughout my
> code, as described here:
> - 
> https://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-cache-api
>
> I'd like the Django ORM to make the API calls for me automatically
> when I call objects.get(), objects.filter(), save(), etc.  I'd hoped to 
> enable it simply by adding middleware or a custom manager or 
> something.
>
> Any suggestions?  I feel like I may be missing something obvious.
>
> --Fred 
> --
> Fred Stluka -- mailt...@bristle.com  -- 
> http://bristle.com/~fred/ 
> Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
> Open Source: Without walls and fences, we need no Windows or Gates. 
> --
>
>

-- 
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/c778bee7-eb39-4d95-ba23-acfb5e998dc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python dictionaries saved to models

2016-08-17 Thread Tim Graham
You need to transform your data dictionary so that the keys match the 
models field names and then you can use:

players_data = [{'number': 1, ...}, {...}]

for data in players_data:
Player.objects.bulk_create(**data)

(or something similar with bulk_create())

https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create

On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg wrote:
>
> Hi everyone,
>
> I have several dictionaries that I would like to import into my django 
> project database, but I can't figure out exactly how.
>
> I have tried to implement through fixtures, through views and through 
> loaddata, but I must be doing something wrong at every turn- so if someone 
> could suggest a workflow, it would really help me a lot!
>
> My data is currently in a list of dictionaries called data:
>
> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 
> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 'university'
> , 'number': 10, 'exp': 1},
>
>
> each dictionary within that list is a "player" who I'd like to input his 
> data into my model "Players"
>
> Enter code here...
> #models.py
> class Player(models.Model):
>
> number = models.CharField(max_length=2)
> player = models.CharField(max_length=50)
> position = models.CharField(max_length=2)
> height = models.CharField(max_length=50)
> weight = models.CharField(max_length=50)
> birth = models.DateField()
> exp = models.CharField(max_length=50)
> college = models.CharField(max_length=50)
> def __str__(self):
> return self.player
>
>
> There are about 500 players in that list of dictionaries above that I 
> would like to insert into this model.
>
> 1) Can i run a function in the model above to insert the data into its 
> appropriate field?  If so, how do I execute that function?
> 2) If it's a view that I need to execute-  do I just put the function in 
> views.py?  How then is the dictionary imported into the database?
>
> or... How would you go about getting that data into your database?  Please 
> note that the data is coming from a url that might change from time to 
> time.  But I think once i get the first iteration of data into these models 
> I can figure out how to update.  But the only way I can figure out is to 
> create them one by one in the shell or create a form and input them one by 
> one.
>
> If you have a solution, please share and be as detailed as possible since 
> I am a complete beginner with django.
>
> Peace and love,
>
> Aaron
>
>

-- 
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/2997731e-ef1f-47b4-a3a7-e12362985b88%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-17 Thread Matt
Ok a step forward. When I spell out the tests it works: 

https://dpaste.de/2MXf

But when I run test without arguments, it fails out:

https://dpaste.de/cgTH

There is more than the backups app here, but I plan to replicate out the 
fix when I get it.

On Wednesday, August 17, 2016 at 2:34:45 PM UTC-6, Fred Stluka wrote:
>
> Matt,
>
> Oops!  Right.  I just noticed that in the dpaste.
>
> My next guess is you may need to change the name "good_index_text"
> to something that starts with "test_" to get it to be recognized as a 
> test.
>
> Or maybe something to do with "refreshes"?  The test trace shows
> it trying to run testcase "refreshes.backups.tests", but in the manual
> import you did from the python shell, you only import "backups.tests"
>
> --Fred 
> --
> Fred Stluka -- mailt...@bristle.com  -- 
> http://bristle.com/~fred/ 
> Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
> Open Source: Without walls and fences, we need no Windows or Gates. 
> --
>
> On 8/17/16 4:27 PM, Matt wrote:
>
> Sorry for the typo, but I have already do that way. I have the output in 
> the the first link.
>
> On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote: 
>>
>> Matt,
>>
>> Drop the "s" from "tests":
>>
>> ./manage.py test backups
>>
>> --Fred 
>> --
>> Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/ 
>> Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
>> Open Source: Without walls and fences, we need no Windows or Gates. 
>> --
>>
>> On 8/17/16 4:17 PM, Matt wrote:
>>
>> When I'm trying to get tests to work it simply states that its unable to 
>> import .tests. I'm not sure what I'm missing here. Here is some output 
>> please let me know if you need more: 
>>
>> ./manage.py tests backups
>> https://dpaste.de/4U9C
>>
>> The test file:
>> https://dpaste.de/bBZt
>> -- 
>> 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/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%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/404f7e22-6f34-4c0d-bfdd-f277f6fb7543%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Database data caching in Django?...

2016-08-17 Thread Avraham Serour
https://djangopackages.org/grids/g/caching/


On Wed, Aug 17, 2016 at 11:43 PM, Tim Graham  wrote:

> I did a quick search and found https://github.com/BertrandBordage/django-
> cachalot. Does it meet your requirements?
>
>
> On Wednesday, August 17, 2016 at 3:34:33 PM UTC-4, Fred Stluka wrote:
>
>> Django users,
>>
>> Is there an easy way to enable an automatic write-through
>> database cache in Django?
>>
>> I'd want memcached or something to cache all data read by the
>> Django ORM and use the cached copy on future reads, and of
>> course update the cache as well as the DB (a "write-through"
>> cache) when writing data.
>>
>> Is there a piece of middleware I can activate to cause the ORM
>> to do this automatically for all DB queries?  Thanks!
>>
>> Details:
>>
>> I'm interested in caching the results of queries to the DB, not
>> caching the results of templates or views.  So, it is different
>> from the following, which I already know how to do:
>> - Caching of template files:
>>- http://us5.campaign-archive1.com/?u=a8d4be66d1927077a9255182
>> d&id=a6f7d644a7&e=c90970e145
>>- https://docs.djangoproject.com/en/dev/ref/templates/api/#dja
>> ngo.template.loaders.cached.Loader
>> - Caching of all Django views for an entire site:
>>- https://docs.djangoproject.com/en/dev/topics/cache/#the-per-
>> site-cache
>> - Caching of specific Django views:
>>   - https://docs.djangoproject.com/en/dev/topics/cache/#the-per-
>> view-cache
>> - Caching of fragments of a Django Template:
>>   - https://docs.djangoproject.com/en/dev/topics/cache/#template
>> -fragment-caching
>>
>> I'm also hoping to not have to add cache API calls throughout my
>> code, as described here:
>> - https://docs.djangoproject.com/en/dev/topics/cache/#the-low-
>> level-cache-api
>>
>> I'd like the Django ORM to make the API calls for me automatically
>> when I call objects.get(), objects.filter(), save(), etc.  I'd hoped to
>> enable it simply by adding middleware or a custom manager or
>> something.
>>
>> Any suggestions?  I feel like I may be missing something obvious.
>>
>> --Fred
>> --
>> Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/
>> Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
>> Open Source: Without walls and fences, we need no Windows or Gates.
>> --
>>
>> --
> 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/c778bee7-eb39-4d95-ba23-acfb5e998dc8%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/CAFWa6tLLJ28%3DPdaZ8TOMv9XkwA4WK8a8cu320qSm-QEaCbPevQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-17 Thread ludovic coues
Ok, sorry, I made a off by one error on the link :)

Try that:

# shops/admin.py
from django.contrib import admin
from products.models import Product
from .models import Shop

class ShopAdmin(admin.ModelAdmin):
def formfield_for_manytomany(self, db_field, request, **kwargs):
if db_field.name == "product":
kwargs["queryset"] = Product.objects.filter(user=request.user)
return super(ShopAdmin,
self).formfield_for_manytomany(db_field, request, **kwargs)

admin.site.register(Shop, ShopAdmin)

###

It should give you the desired result

2016-08-17 19:31 GMT+02:00 Shamaila Moazzam :
>
> shops/admin.py
> from .models import Shop
>
> admin.site.register(Shop)
>
>
> products/admin.py
>
>
> from .models import Product, Variation, ProductImage, Category,
> ProductFeatured, color_product, size_product
>
>
>
> class ProductImageInline(admin.TabularInline):
> model = ProductImage
> extra = 0
> max_num = 10
>
> class VariationInline(admin.TabularInline):
> model = Variation
> extra = 0
> max_num = 10
>
>
> class ProductAdmin(admin.ModelAdmin):
> list_display = ['__unicode__', 'price',]
> inlines = [
> ProductImageInline,
> VariationInline,
>
>
> ]
> class Meta:
> model = Product
>
>
> admin.site.register(Product, ProductAdmin)
>
>
>
>
> #admin.site.register(Variation)
>
> admin.site.register(ProductImage)
>
>
> admin.site.register(Category)
>
>
> admin.site.register(ProductFeatured)
>
> admin.site.register(color_product)
>
> admin.site.register(size_product)
>
> On Wednesday, August 17, 2016 at 9:23:31 PM UTC+5, ludovic coues wrote:
>>
>> Could you share your admin.py file ?
>>
>> You might be interested into this part of the documentation:
>>
>> https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey
>>
>> 2016-08-17 17:20 GMT+02:00 Shamaila Moazzam :
>> > @Ludovic there is no error. Just I don't want to get all the products
>> > pre-populated. I need empty products field and only when user uploads
>> > products then it should show me products. Please advise
>> >
>> > On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam
>> > wrote:
>> >>
>> >> Hi,
>> >>
>> >> I am a beginner and please forgive me if my question is not up to the
>> >> standard. I've got two models one is Product which is saved in db
>> >> already
>> >> and another one is Shop. I am trying to related both models with
>> >> following
>> >> code.
>> >>
>> >> class Product(models.Model):
>> >> user = models.ForeignKey(settings.USER_AUTH_MODEL)
>> >> title = models.CharField(max_length=120)
>> >> description = models.TextField(blank=True, null=True)
>> >> price = models.DecimalField(decimal_places=2, max_digits=20)
>> >> publish_date = models.DateTimeField(auto_now=False,
>> >> auto_now_add=False, null=True, blank= True)
>> >> expire_date = models.DateTimeField(auto_now=False,
>> >> auto_now_add=False,
>> >> null=True, blank=True)
>> >> active = models.BooleanField(default=True)
>> >> categories = models.ManyToManyField('Category', blank=True)
>> >> default = models.ForeignKey('Category',
>> >> related_name='default_category', null=True, blank=True)
>> >> hitcounts = GenericRelation(HitCount,
>> >> content_type_field='content_type', object_id_field='object_pk',)
>> >>
>> >>
>> >> objects = ProductManager()
>> >>
>> >>
>> >> class Meta:
>> >> ordering = ["-title"]
>> >>
>> >>
>> >> def __unicode__(self):
>> >> return self.title
>> >>
>> >>
>> >> class Shop(models.Model):
>> >> product = models.ManyToManyField(Product)
>> >>
>> >> title = models.CharField(max_length=120, null=False)
>> >> image = models.ImageField(upload_to=image_upload_to_shop,
>> >> null=True)
>> >> location = models.CharField(max_length=120)
>> >>
>> >>
>> >>
>> >>
>> >> def __unicode__(self):
>> >> return str(self.title)
>> >>
>> >>
>> >>
>> >>
>> >> With above I've got it added in my admin.py for Shop app and now I have
>> >> a
>> >> problem. When I add a shop it shows all the past products prepopulated
>> >> in my
>> >> "products" field.
>> >> I just need to add the products that shop account holder has uploaded.
>> >> I
>> >> wish to use django\s built-in auth model to register shop holders.
>> >> Again the
>> >> confusion is that where should I add
>> >> USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app then
>> >> for beginner like me it will be easy to use querysets. Please advise
>> >> the
>> >> best practice for above scenario.
>> >
>> > --
>> > 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
>> >
>>

Re: connecting to mssql database

2016-08-17 Thread sum abiut
I am getting the error mes

django.db.utils.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data
source name not found, and no default driver specified (0)
(SQLDriverConnect)')sage




On Wed, Aug 17, 2016 at 11:17 PM, Daniel França 
wrote:

> What errors are you getting?
>
> On Wed, 17 Aug 2016 at 14:15 sum abiut  wrote:
>
>>
>> Hi,
>> i am having a very hard time figuring out how to connect to a mssql
>> database. i've try following this guide but nothing seems to be working.
>> please help
>>
>> http://www.tivix.com/blog/getting-django-working-with-mssql-pyodbc/
>>
>> https://pypi.python.org/pypi/django-pyodbc-azure
>>
>> cheers,
>>
>> --
>> 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/CAPCf-y5M37%2B9JRspvMEtUUOZVOp1SaUSuToGs0V
>> dH%2B_DydPC8A%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CACPst9LGPZTHHcKDB0EVUpgrEdrBz
> TtMFxeCib4WScSEqWf5Mg%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-

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


Re: connecting to mssql database

2016-08-17 Thread sum abiut
now i have made changes to settings file

DATABASES = {
'default': {
'ENGINE': 'django_pyodbc',
'NAME': xxx',
'USER': 'xx',
'PASSWORD': 'xx',
'HOST': 'xxx',
'PORT': '1433',

'OPTIONS': {
'host_is_server': True,
}
}
}



and i am getting the error :
File
"/var/www/mssqlconnect/local/lib/python2.7/site-packages/django_pyodbc/base.py",
line 96, in 
raise ImproperlyConfigured("Django %d.%d is not supported." %
DjangoVersion[:2])
django.core.exceptions.ImproperlyConfigured: Django 1.10 is not supported.


is this something has to do with version issue?

cheers



On Thu, Aug 18, 2016 at 8:44 AM, sum abiut  wrote:

> I am getting the error mes
>
> django.db.utils.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data
> source name not found, and no default driver specified (0)
> (SQLDriverConnect)')sage
>
>
>
>
> On Wed, Aug 17, 2016 at 11:17 PM, Daniel França 
> wrote:
>
>> What errors are you getting?
>>
>> On Wed, 17 Aug 2016 at 14:15 sum abiut  wrote:
>>
>>>
>>> Hi,
>>> i am having a very hard time figuring out how to connect to a mssql
>>> database. i've try following this guide but nothing seems to be working.
>>> please help
>>>
>>> http://www.tivix.com/blog/getting-django-working-with-mssql-pyodbc/
>>>
>>> https://pypi.python.org/pypi/django-pyodbc-azure
>>>
>>> cheers,
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/CAPCf-y5M37%2B9JRspvMEtUUOZVOp1SaUSuToGs0Vd
>>> H%2B_DydPC8A%40mail.gmail.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/CACPst9LGPZTHHcKDB0EVUpgrEdrBzTtMFxeCib4WSc
>> SEqWf5Mg%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -
>

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


MIDDLEWARE vs MIDDLEWARE_CLASSES: 'WSGIRequest' object has no attribute 'user'

2016-08-17 Thread Andrew Emory
My settings.py file has the default MIDDLEWARE settings generated by 
django-admin startapp:

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

But when I visit /admin I get an Attribute Error with a traceback that 
lists 

Installed Middleware:
['django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware']

And Request_Information - Settings that lists: 
MIDDLEWARE_CLASSES 

['django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware']


I am thinking of editing my settings file to read MIDDLEWARE_CLASSES 
instead of MIDDLEWARE (because of stack-overflow articles) but according to 
the Django Documentation that will only sweep the problem under the rug 
rather than addressing the issue.  I don't see why, at this point, I should 
deviate from the default settings.  Or, what caused the problem in the 
first place.

Any help would be appreciated.

-- 
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/7dfa64c2-e80f-4426-8cbc-8d1b4bb3b20d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django query not returning all objects

2016-08-17 Thread Koonal Bharadwaj
Hello,

The issue:

When trying to order_by on a related model duplicate entries are created. I 
solved this with an OrderedSet that is applied after paginating (
http://code.activestate.com/recipes/576694/). However, when I try to 
paginate the queryset, all the results are not returned. It's missing a few 
table rows. 

Models:

class HeartFlowCase(models.Model):
"""
 
A Hearflow Case.
 
This serves at the true state of a case as it is processed through the 
system.
It also holds the results of each step of the processing.

"""

# Primary
hf_id = models.CharField('HeartFlow ID', max_length=200, blank=True, 
unique=True)
canonical_data = models.ForeignKey('cases.CaseData', to_field='uuid', 
related_name="canonical_data")


class CaseData(models.Model):
"""
Extracted and computed values related to a single processing run of a case.

A HeartFlowCase can have multiple runs associated with it.
The one which is accepted to be the "clinically accurate" one is the one 
referred to as 'canonical_data' by
the HeartFlowCase itself.

"""

# Primary
heartflowcase = models.ForeignKey(HeartFlowCase, related_name='data', 
blank=True, null=True)
uuid = models.CharField('Case Data UUID', max_length=200, blank=False, 
null=False, unique=True)
deadline = models.DateTimeField('Deadline', blank=True, 
default=get_default_deadline)


As you can see, there is a ForeignKey to canonical CaseData from 
HeartFlowCase and a ForeignKey to HeartFlowCase from CaseData. So you can 
have multiple CaseDatas per HeartFlowCase. 

Structure:

HeartFlowCase
|
data - CaseData1
\
 \ CaseData2


For example: 

Total number of HeartFlow objects are 5 with 2 CaseDatas each. If I 
order_by deadline on CaseData as: 
cases = HeartFlowCase.objects.all().order_by(data__deadline)
this returns duplicates since there are multiple CaseDatas, which is fine. 
Now I try and paginate it by applying:

paginator = Paginator(cases, 2)
cases = paginator.page(1)

Now the SQL query has a LIMIT and OFFSET given. If the order_by gives duplicate 
HeartFlowCase objects this hits the LIMIT number and the results that are 
returned are missing a HeartFlowCase object. So if 2 duplicates are returned 
per case after applying the OrderedSet I get only one case back and missing one 
case since it was never returned from the database. As I goto the next page:

cases = paginator.page(2)

that missingHeartFlowCase object that was not returned from the first page 
queryset is lost forever and is never displayed. 


I hope this is clear. Please let me know if I can clarify further. Any help 
would greatly be appreciated. 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/61ec03f6-3325-49fe-bcdc-a7ca50784dc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with django form an ajax, error 500

2016-08-17 Thread agapito treviño
Elros Romeo

as defined by the form.as_p.?
I want to implement this



El viernes, 15 de julio de 2016, 18:49:00 (UTC-5), Elros Romeo escribió:
>
> Hi, i hope you can help me, im trying to make a django post form without 
> reloading the page using ajax, but im getting error 500 when submit, can 
> you help me to fix this, this is my code:
>
> *models.py*
>
> class ProductoConcepto(models.Model):
> producto = models.ForeignKey(Producto)
> orden = models.ForeignKey(Cobro)
> cantidad = models.FloatField()
>
>
> *urls.py*
>
> from django.conf.urls import patterns, include, url
> from django.contrib import admin
> from cobro import views
>
> urlpatterns = [
> url(r'^cobro/agregar_concepto/$', views.addconcept_product, 
> name='add_concepto'),
> ]
>
> *views.py*
>
>
> def addconcept_product(request):
>
> if request.method == 'POST':
>
> if form.is_valid():
> producto = request.POST['producto']
> orden = request.POST['orden']
> cantidad = request.POST['cantidad']
>
> ProductoConcepto.objects.create(producto=producto, 
> orden=orden, cantidad=cantidad)
>
> return HttpResponse('')
>
> *template*
>
>  role="dialog"  aria-hidden="true">
> 
> 
> 
>  data-dismiss="modal">
> ×
> Cerrar
> 
> Agregar nuevo concepto
> 
> 
> Datos de concepto a agregar:
> 
>  enctype='multipart/form-data'>
> {% csrf_token %}
> {{form2.as_p}}
>
> 
> 
> 
>
> 
>  value='Guardar' class="btn btn-w-m btn-primary"/>
> 
>
> 
> 
> 
> 
> 
> 
>
> 
> $(document).on('submit', '#formulario-modal', function(e){
> e.preventDefault();
> $.ajax ({
> type: 'POST',
> url: '{% url 'add_concepto' %}',
> data: {
> producto: $('#id_producto').val(),
> orden: $('#id_orden').val(),
> cantidad: $('#id_cantidad').val(),
> csrfmiddlewaretoken: '{{ csrf_token }}',
> },
> sucess:function(){
> alert("OK");
> }
> })
> });
>
> 
>
> this is the error:  POST http://127.0.0.1:8000/cobro/agregar_concepto/ 
> 500 (Internal Server Error)
>

-- 
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/31b0adb6-468c-4757-b470-01b9aaa047f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with django form an ajax, error 500

2016-08-17 Thread Constantine Covtushenko
Hi Andrew,

To have a proper `to_python` transformation from `POST` strings please use 
forms.
They do that perfectly and also they can handle any king of user input 
validations.


form = SomeCustomForm(request.POST)
form.is_valid():
parsed_dictionary = form.cleaned_data()


As for 'Ajax'. It seems like you should manually parse body before any 
further processing. Request instance has `is_ajax 
`
 
method to detect such requests.

That can be done
import json
if request.is_ajax():
json_dict =  

On Thursday, August 18, 2016 at 4:34:33 AM UTC+3, agapito treviño wrote:
>
> Elros Romeo
>
> as defined by the form.as_p.?
> I want to implement this
>
>
>
> El viernes, 15 de julio de 2016, 18:49:00 (UTC-5), Elros Romeo escribió:
>>
>> Hi, i hope you can help me, im trying to make a django post form without 
>> reloading the page using ajax, but im getting error 500 when submit, can 
>> you help me to fix this, this is my code:
>>
>> *models.py*
>>
>> class ProductoConcepto(models.Model):
>> producto = models.ForeignKey(Producto)
>> orden = models.ForeignKey(Cobro)
>> cantidad = models.FloatField()
>>
>>
>> *urls.py*
>>
>> from django.conf.urls import patterns, include, url
>> from django.contrib import admin
>> from cobro import views
>>
>> urlpatterns = [
>> url(r'^cobro/agregar_concepto/$', views.addconcept_product, 
>> name='add_concepto'),
>> ]
>>
>> *views.py*
>>
>>
>> def addconcept_product(request):
>>
>> if request.method == 'POST':
>>
>> if form.is_valid():
>> producto = request.POST['producto']
>> orden = request.POST['orden']
>> cantidad = request.POST['cantidad']
>>
>> ProductoConcepto.objects.create(producto=producto, 
>> orden=orden, cantidad=cantidad)
>>
>> return HttpResponse('')
>>
>> *template*
>>
>> > role="dialog"  aria-hidden="true">
>> 
>> 
>> 
>> > data-dismiss="modal">
>> ×
>> Cerrar
>> 
>> Agregar nuevo 
>> concepto
>> 
>> 
>> Datos de concepto a agregar:
>> 
>> > enctype='multipart/form-data'>
>> {% csrf_token %}
>> {{form2.as_p}}
>>
>> 
>> 
>> 
>>
>> 
>> > value='Guardar' class="btn btn-w-m btn-primary"/>
>> 
>>
>> 
>> 
>> 
>> 
>> 
>> 
>>
>> 
>> $(document).on('submit', '#formulario-modal', function(e){
>> e.preventDefault();
>> $.ajax ({
>> type: 'POST',
>> url: '{% url 'add_concepto' %}',
>> data: {
>> producto: $('#id_producto').val(),
>> orden: $('#id_orden').val(),
>> cantidad: $('#id_cantidad').val(),
>> csrfmiddlewaretoken: '{{ csrf_token }}',
>> },
>> sucess:function(){
>> alert("OK");
>> }
>> })
>> });
>>
>> 
>>
>> this is the error:  POST http://127.0.0.1:8000/cobro/agregar_concepto/ 
>> 500 (Internal Server Error)
>>
>

-- 
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/238ddd6d-a084-422a-b40c-0cbc06ff9002%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with django form an ajax, error 500

2016-08-17 Thread Constantine Covtushenko
Sorry guys, please skip my previous post. It appeared unfinished.
My correct one below.

Hi Andrew,

To have a proper `to_python` transformation from `POST` strings please use 
forms.
They do that perfectly and also they can handle any king of user input 
validations.

form = SomeCustomForm(request.POST)
if form.is_valid():

parsed_dictionary = form.cleaned_data()

//some other required stuff 



As for 'Ajax'. It seems like you should manually parse body before any 
further processing. Request instance has `is_ajax 
`
 
method to detect such requests.

That can be done
import json
if request.is_ajax():

query_dict =  json.loads(request.body)


I hope it helps.

Regards,
Constantine C.

On Thursday, August 18, 2016 at 4:34:33 AM UTC+3, agapito treviño wrote:
>
> Elros Romeo
>
> as defined by the form.as_p.?
> I want to implement this
>
>
>
> El viernes, 15 de julio de 2016, 18:49:00 (UTC-5), Elros Romeo escribió:
>>
>> Hi, i hope you can help me, im trying to make a django post form without 
>> reloading the page using ajax, but im getting error 500 when submit, can 
>> you help me to fix this, this is my code:
>>
>> *models.py*
>>
>> class ProductoConcepto(models.Model):
>> producto = models.ForeignKey(Producto)
>> orden = models.ForeignKey(Cobro)
>> cantidad = models.FloatField()
>>
>>
>> *urls.py*
>>
>> from django.conf.urls import patterns, include, url
>> from django.contrib import admin
>> from cobro import views
>>
>> urlpatterns = [
>> url(r'^cobro/agregar_concepto/$', views.addconcept_product, 
>> name='add_concepto'),
>> ]
>>
>> *views.py*
>>
>>
>> def addconcept_product(request):
>>
>> if request.method == 'POST':
>>
>> if form.is_valid():
>> producto = request.POST['producto']
>> orden = request.POST['orden']
>> cantidad = request.POST['cantidad']
>>
>> ProductoConcepto.objects.create(producto=producto, 
>> orden=orden, cantidad=cantidad)
>>
>> return HttpResponse('')
>>
>> *template*
>>
>> > role="dialog"  aria-hidden="true">
>> 
>> 
>> 
>> > data-dismiss="modal">
>> ×
>> Cerrar
>> 
>> Agregar nuevo 
>> concepto
>> 
>> 
>> Datos de concepto a agregar:
>> 
>> > enctype='multipart/form-data'>
>> {% csrf_token %}
>> {{form2.as_p}}
>>
>> 
>> 
>> 
>>
>> 
>> > value='Guardar' class="btn btn-w-m btn-primary"/>
>> 
>>
>> 
>> 
>> 
>> 
>> 
>> 
>>
>> 
>> $(document).on('submit', '#formulario-modal', function(e){
>> e.preventDefault();
>> $.ajax ({
>> type: 'POST',
>> url: '{% url 'add_concepto' %}',
>> data: {
>> producto: $('#id_producto').val(),
>> orden: $('#id_orden').val(),
>> cantidad: $('#id_cantidad').val(),
>> csrfmiddlewaretoken: '{{ csrf_token }}',
>> },
>> sucess:function(){
>> alert("OK");
>> }
>> })
>> });
>>
>> 
>>
>> this is the error:  POST http://127.0.0.1:8000/cobro/agregar_concepto/ 
>> 500 (Internal Server Error)
>>
>

-- 
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/743add14-54a3-427f-9b2c-5b1b38cd676a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django query not returning all objects

2016-08-17 Thread Constantine Covtushenko
Hi Koonal,

As said in django doc
 you
can use `distinct()` to remove duplicated rows from first query.

I believe with this your pagination should works as expected.

Regards,


On Thu, Aug 18, 2016 at 2:58 AM, Koonal Bharadwaj 
wrote:

> Hello,
>
> The issue:
>
> When trying to order_by on a related model duplicate entries are created.
> I solved this with an OrderedSet that is applied after paginating (
> http://code.activestate.com/recipes/576694/). However, when I try to
> paginate the queryset, all the results are not returned. It's missing a few
> table rows.
>
> Models:
>
> class HeartFlowCase(models.Model):
> """
>
> A Hearflow Case.
>
> This serves at the true state of a case as it is processed through the 
> system.
> It also holds the results of each step of the processing.
>
> """
>
> # Primary
> hf_id = models.CharField('HeartFlow ID', max_length=200, blank=True, 
> unique=True)
> canonical_data = models.ForeignKey('cases.CaseData', to_field='uuid', 
> related_name="canonical_data")
>
>
> class CaseData(models.Model):
> """
> Extracted and computed values related to a single processing run of a 
> case.
>
> A HeartFlowCase can have multiple runs associated with it.
> The one which is accepted to be the "clinically accurate" one is the one 
> referred to as 'canonical_data' by
> the HeartFlowCase itself.
>
> """
>
> # Primary
> heartflowcase = models.ForeignKey(HeartFlowCase, related_name='data', 
> blank=True, null=True)
> uuid = models.CharField('Case Data UUID', max_length=200, blank=False, 
> null=False, unique=True)
> deadline = models.DateTimeField('Deadline', blank=True, 
> default=get_default_deadline)
>
>
> As you can see, there is a ForeignKey to canonical CaseData from
> HeartFlowCase and a ForeignKey to HeartFlowCase from CaseData. So you can
> have multiple CaseDatas per HeartFlowCase.
>
> Structure:
>
> HeartFlowCase
> |
> data - CaseData1
> \
>  \ CaseData2
>
>
> For example:
>
> Total number of HeartFlow objects are 5 with 2 CaseDatas each. If I
> order_by deadline on CaseData as:
> cases = HeartFlowCase.objects.all().order_by(data__deadline)
> this returns duplicates since there are multiple CaseDatas, which is fine.
> Now I try and paginate it by applying:
>
> paginator = Paginator(cases, 2)
> cases = paginator.page(1)
>
> Now the SQL query has a LIMIT and OFFSET given. If the order_by gives 
> duplicate HeartFlowCase objects this hits the LIMIT number and the results 
> that are returned are missing a HeartFlowCase object. So if 2 duplicates are 
> returned per case after applying the OrderedSet I get only one case back and 
> missing one case since it was never returned from the database. As I goto the 
> next page:
>
> cases = paginator.page(2)
>
> that missingHeartFlowCase object that was not returned from the first page 
> queryset is lost forever and is never displayed.
>
>
> I hope this is clear. Please let me know if I can clarify further. Any help 
> would greatly be appreciated. 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/61ec03f6-3325-49fe-bcdc-a7ca50784dc0%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/CAK52boUF2mNVaU-06TWebfH5JonHvFmdqW103Q_CF1WmWShjJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-17 Thread Gergely Polonkai
Hello,

this “refreshes.backups.tests” thing bothers me a lot. Could you show us
your directory structure, please?

Best,
Gergely

On Wed, Aug 17, 2016, 23:03 Matt  wrote:

> Ok a step forward. When I spell out the tests it works:
>
> https://dpaste.de/2MXf
>
> But when I run test without arguments, it fails out:
>
> https://dpaste.de/cgTH
>
> There is more than the backups app here, but I plan to replicate out the
> fix when I get it.
>
> On Wednesday, August 17, 2016 at 2:34:45 PM UTC-6, Fred Stluka wrote:
>
>> Matt,
>>
>> Oops!  Right.  I just noticed that in the dpaste.
>>
>> My next guess is you may need to change the name "good_index_text"
>> to something that starts with "test_" to get it to be recognized as a
>> test.
>>
>> Or maybe something to do with "refreshes"?  The test trace shows
>> it trying to run testcase "refreshes.backups.tests", but in the manual
>> import you did from the python shell, you only import "backups.tests"
>>
>> --Fred
>> --
>>
> Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/
>> Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
>> Open Source: Without walls and fences, we need no Windows or Gates.
>> --
>>
>> On 8/17/16 4:27 PM, Matt wrote:
>>
> Sorry for the typo, but I have already do that way. I have the output in
>> the the first link.
>>
>> On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote:
>>>
>>> Matt,
>>>
>>> Drop the "s" from "tests":
>>>
>>> ./manage.py test backups
>>>
>>> --Fred
>>> --
>>> Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/
>>> Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
>>> Open Source: Without walls and fences, we need no Windows or Gates.
>>> --
>>>
>>> On 8/17/16 4:17 PM, Matt wrote:
>>>
>>> When I'm trying to get tests to work it simply states that its unable to
>>> import .tests. I'm not sure what I'm missing here. Here is some output
>>> please let me know if you need more:
>>>
>>> ./manage.py tests backups
>>> https://dpaste.de/4U9C
>>>
>>> The test file:
>>> https://dpaste.de/bBZt
>>> --
>>> 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/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>>
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%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/404f7e22-6f34-4c0d-bfdd-f277f6fb7543%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/CACczBUKXpd-MKGXNDyNTSXiBcKQ-u7r1VF2wQCKKBq1PFCz4BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python dictionaries saved to models

2016-08-17 Thread Aaron Weisberg
Great- thanks Tim.

I understand the Python, but what I guess where I'm fuzzy is where to 
exactly put that code.  

Do I put it in the models.py? class.py?  and how do I execute?

That is the final piece of the puzzle for me.  

Thanks so much.

Aaron

On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote:
>
> You need to transform your data dictionary so that the keys match the 
> models field names and then you can use:
>
> players_data = [{'number': 1, ...}, {...}]
>
> for data in players_data:
> Player.objects.bulk_create(**data)
>
> (or something similar with bulk_create())
>
> https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create
>
> On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg wrote:
>>
>> Hi everyone,
>>
>> I have several dictionaries that I would like to import into my django 
>> project database, but I can't figure out exactly how.
>>
>> I have tried to implement through fixtures, through views and through 
>> loaddata, but I must be doing something wrong at every turn- so if someone 
>> could suggest a workflow, it would really help me a lot!
>>
>> My data is currently in a list of dictionaries called data:
>>
>> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 
>> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 
>> 'university', 'number': 10, 'exp': 1},
>>
>>
>> each dictionary within that list is a "player" who I'd like to input his 
>> data into my model "Players"
>>
>> Enter code here...
>> #models.py
>> class Player(models.Model):
>>
>> number = models.CharField(max_length=2)
>> player = models.CharField(max_length=50)
>> position = models.CharField(max_length=2)
>> height = models.CharField(max_length=50)
>> weight = models.CharField(max_length=50)
>> birth = models.DateField()
>> exp = models.CharField(max_length=50)
>> college = models.CharField(max_length=50)
>> def __str__(self):
>> return self.player
>>
>>
>> There are about 500 players in that list of dictionaries above that I 
>> would like to insert into this model.
>>
>> 1) Can i run a function in the model above to insert the data into its 
>> appropriate field?  If so, how do I execute that function?
>> 2) If it's a view that I need to execute-  do I just put the function in 
>> views.py?  How then is the dictionary imported into the database?
>>
>> or... How would you go about getting that data into your database? 
>>  Please note that the data is coming from a url that might change from time 
>> to time.  But I think once i get the first iteration of data into these 
>> models I can figure out how to update.  But the only way I can figure out 
>> is to create them one by one in the shell or create a form and input them 
>> one by one.
>>
>> If you have a solution, please share and be as detailed as possible since 
>> I am a complete beginner with django.
>>
>> Peace and love,
>>
>> Aaron
>>
>>

-- 
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/44dbbe95-c5ae-4282-8e70-d9e5795720e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Non relational databases (MongoDB) with Django

2016-08-17 Thread Jani Tiainen

Hi,

Django ORM is designed for relational data, for database engines like 
Postgres, MySQL, Oracle etc. MongoDB is document oriented database. In 
theory partial support for relational data could be implemented to be 
able to use mongodb but it would be relative way. Which leads to 
question that other response asked, if you want ORM and relational data, 
why not to use real relational database which works perfectly with 
Django ORM from the beginning?



On 17.08.2016 15:32, Deep Shah wrote:
How easy is it to use MongoDb without a Django ORM once the code base 
increases?





On Wednesday, August 17, 2016 at 5:25:01 PM UTC+5:30, Jani Tiainen wrote:

Hi,

Well you can use non relational databases with django. This of
course means that you don't have ORM for that, use them as is. Way
simpler than trying to force ORM (which stands for object
relational mapper) to follow something non relational.

Also, if you're not stuck at mongodb, you may find arangodb much
more appealing and doing most things "right".


On 17.08.2016 11:28, Deep Shah wrote:

I want to use MongoDB with Django. Which are the advisable,
latest and stable engines?
I found https://github.com/django-nonrel/mongodb-engine
 which requires
the non relational version of Django
(https://github.com/django-nonrel/django/
). But they have not
updated the code since Django 1.6.
-- 
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/f2a605c0-bcd9-45e9-8927-f9c8f09bc95b%40googlegroups.com

.
For more options, visit https://groups.google.com/d/optout
.


-- 
Jani Tiainen


--
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/92c41fc9-7a2d-4a59-b7ac-132450dd63ef%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
Jani Tiainen

--
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/e1ee2458-3c2e-2d03-03ee-3540ce7ae366%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python dictionaries saved to models

2016-08-17 Thread Todor Velichkov
Maybe a data migration 
 
is what you are looking for.

On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote:
>
> Great- thanks Tim.
>
> I understand the Python, but what I guess where I'm fuzzy is where to 
> exactly put that code.  
>
> Do I put it in the models.py? class.py?  and how do I execute?
>
> That is the final piece of the puzzle for me.  
>
> Thanks so much.
>
> Aaron
>
> On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote:
>>
>> You need to transform your data dictionary so that the keys match the 
>> models field names and then you can use:
>>
>> players_data = [{'number': 1, ...}, {...}]
>>
>> for data in players_data:
>> Player.objects.bulk_create(**data)
>>
>> (or something similar with bulk_create())
>>
>> https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create
>>
>> On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg wrote:
>>>
>>> Hi everyone,
>>>
>>> I have several dictionaries that I would like to import into my django 
>>> project database, but I can't figure out exactly how.
>>>
>>> I have tried to implement through fixtures, through views and through 
>>> loaddata, but I must be doing something wrong at every turn- so if someone 
>>> could suggest a workflow, it would really help me a lot!
>>>
>>> My data is currently in a list of dictionaries called data:
>>>
>>> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 
>>> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 
>>> 'university', 'number': 10, 'exp': 1},
>>>
>>>
>>> each dictionary within that list is a "player" who I'd like to input his 
>>> data into my model "Players"
>>>
>>> Enter code here...
>>> #models.py
>>> class Player(models.Model):
>>>
>>> number = models.CharField(max_length=2)
>>> player = models.CharField(max_length=50)
>>> position = models.CharField(max_length=2)
>>> height = models.CharField(max_length=50)
>>> weight = models.CharField(max_length=50)
>>> birth = models.DateField()
>>> exp = models.CharField(max_length=50)
>>> college = models.CharField(max_length=50)
>>> def __str__(self):
>>> return self.player
>>>
>>>
>>> There are about 500 players in that list of dictionaries above that I 
>>> would like to insert into this model.
>>>
>>> 1) Can i run a function in the model above to insert the data into its 
>>> appropriate field?  If so, how do I execute that function?
>>> 2) If it's a view that I need to execute-  do I just put the function in 
>>> views.py?  How then is the dictionary imported into the database?
>>>
>>> or... How would you go about getting that data into your database? 
>>>  Please note that the data is coming from a url that might change from time 
>>> to time.  But I think once i get the first iteration of data into these 
>>> models I can figure out how to update.  But the only way I can figure out 
>>> is to create them one by one in the shell or create a form and input them 
>>> one by one.
>>>
>>> If you have a solution, please share and be as detailed as possible 
>>> since I am a complete beginner with django.
>>>
>>> Peace and love,
>>>
>>> Aaron
>>>
>>>

-- 
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/2fa36523-26d0-4a2a-9428-b4a5fa88fda1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django query not returning all objects

2016-08-17 Thread Todor Velichkov
Another solution would be to annotate min/max deadline date and order by 
the annotation. Something like:

cases = HeartFlowCase.objects.all().annotate(min_deadline=Min(
'data__deadline')).order_by('min_deadline')


On Thursday, August 18, 2016 at 7:59:19 AM UTC+3, Constantine Covtushenko 
wrote:
>
> Hi Koonal,
>
> As said in django doc 
>  you 
> can use `distinct()` to remove duplicated rows from first query.
>
> I believe with this your pagination should works as expected.
>
> Regards,
>
>
> On Thu, Aug 18, 2016 at 2:58 AM, Koonal Bharadwaj  > wrote:
>
>> Hello,
>>
>> The issue:
>>
>> When trying to order_by on a related model duplicate entries are created. 
>> I solved this with an OrderedSet that is applied after paginating (
>> http://code.activestate.com/recipes/576694/). However, when I try to 
>> paginate the queryset, all the results are not returned. It's missing a few 
>> table rows. 
>>
>> Models:
>>
>> class HeartFlowCase(models.Model):
>> """
>>  
>> A Hearflow Case.
>>  
>> This serves at the true state of a case as it is processed through the 
>> system.
>> It also holds the results of each step of the processing.
>>
>> """
>>
>> # Primary
>> hf_id = models.CharField('HeartFlow ID', max_length=200, blank=True, 
>> unique=True)
>> canonical_data = models.ForeignKey('cases.CaseData', to_field='uuid', 
>> related_name="canonical_data")
>>
>>
>> class CaseData(models.Model):
>> """
>> Extracted and computed values related to a single processing run of a 
>> case.
>>
>> A HeartFlowCase can have multiple runs associated with it.
>> The one which is accepted to be the "clinically accurate" one is the one 
>> referred to as 'canonical_data' by
>> the HeartFlowCase itself.
>>
>> """
>>
>> # Primary
>> heartflowcase = models.ForeignKey(HeartFlowCase, related_name='data', 
>> blank=True, null=True)
>> uuid = models.CharField('Case Data UUID', max_length=200, blank=False, 
>> null=False, unique=True)
>> deadline = models.DateTimeField('Deadline', blank=True, 
>> default=get_default_deadline)
>>
>>
>> As you can see, there is a ForeignKey to canonical CaseData from 
>> HeartFlowCase and a ForeignKey to HeartFlowCase from CaseData. So you 
>> can have multiple CaseDatas per HeartFlowCase. 
>>
>> Structure:
>>
>> HeartFlowCase
>> |
>> data - CaseData1
>> \
>>  \ CaseData2
>>
>>
>> For example: 
>>
>> Total number of HeartFlow objects are 5 with 2 CaseDatas each. If I 
>> order_by deadline on CaseData as: 
>> cases = HeartFlowCase.objects.all().order_by(data__deadline)
>> this returns duplicates since there are multiple CaseDatas, which is 
>> fine. Now I try and paginate it by applying:
>>
>> paginator = Paginator(cases, 2)
>> cases = paginator.page(1)
>>
>> Now the SQL query has a LIMIT and OFFSET given. If the order_by gives 
>> duplicate HeartFlowCase objects this hits the LIMIT number and the results 
>> that are returned are missing a HeartFlowCase object. So if 2 duplicates are 
>> returned per case after applying the OrderedSet I get only one case back and 
>> missing one case since it was never returned from the database. As I goto 
>> the next page:
>>
>> cases = paginator.page(2)
>>
>> that missingHeartFlowCase object that was not returned from the first page 
>> queryset is lost forever and is never displayed. 
>>
>>
>> I hope this is clear. Please let me know if I can clarify further. Any help 
>> would greatly be appreciated. Thanks.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/61ec03f6-3325-49fe-bcdc-a7ca50784dc0%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/61031ac3-18df-43aa-9dc3-08be411863ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.