Re: A server that runs django

2017-02-22 Thread Antonis Christofides
Hi,

For many people, including me, nginx is the recommended web server for Django.
See, for example, my blog post, "Which components should I use in production?
".
You may also be interested in a webinar 
I'm hosting this Tuesday, in which we will deploy Django with nginx and 
Gunicorn.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 02/22/2017 05:53 PM, Luvpreet Singh wrote:
> Yeah I am running my django on nginx. I just wanted to make sure that if I'm
> doing wrong by doing so?
>
>
> On Tuesday, February 7, 2017 at 1:08:01 AM UTC+5:30, Dário Carvalho wrote:
>
> Hi everyone. So, I now understand a little more about how django works and
> I was thinking about how can I run a site built with django in my own
> python's server.
> Someone know how can I do such thing? I thought about using asyncio and/or
> socketserver or even http with socketserver. Anyway, 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/d50fffbb-df42-4287-82ad-5e9175ea2967%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/561c4f5b-66f2-2604-63fd-e1772cbea0a2%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: django channels in the shell

2017-02-22 Thread Andrew Godwin
I would recommend using the channel layer object directly instead in future:

from channels.asgi import get_channel_layer
channel_layer = get_channel_layer()

That will make sure all settings are applied the same.

Andrew

On Wed, Feb 22, 2017 at 8:19 PM, chris rose 
wrote:

> solved it.. I had to explicitly add the hosts parameter
>
> from django.conf import settings
>
>> from django.utils.module_loading import import_string
>
> config = getattr(settings, "CHANNEL_LAYERS", {})
>
>> hosts = config['default']['CONFIG']['hosts']
> backend_class = import_string(config['default']['BACKEND'])
>
>> channel_layer = backend_class(hosts=hosts)
>
>>
> channel = channel_layer.group_channels('poll')[0]
> channel_layer.send(channel, {"text": "hello world!"})
>
> --
> 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/b4e8cb61-4428-48d6-aeb9-463e21398dfe%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/CAFwN1uqBhrtM%3DLSr-_f68etmvJWRANQwMVCJxPSX1cO17q6DRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django channels in the shell

2017-02-22 Thread chris rose
solved it.. I had to explicitly add the hosts parameter

from django.conf import settings

> from django.utils.module_loading import import_string

config = getattr(settings, "CHANNEL_LAYERS", {})

> hosts = config['default']['CONFIG']['hosts']
backend_class = import_string(config['default']['BACKEND'])

> channel_layer = backend_class(hosts=hosts)

>
channel = channel_layer.group_channels('poll')[0]
channel_layer.send(channel, {"text": "hello world!"})

-- 
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/b4e8cb61-4428-48d6-aeb9-463e21398dfe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template language resolve url

2017-02-22 Thread chris rose
sorry i typed an s in there, here is that code amended
 

> 
>

-- 
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/2d5bcf19-2c0b-40a6-8ed4-5e27d4940ab8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template language resolve url

2017-02-22 Thread chris rose
hey xyron..

i replied to your other thread

your namespace should actually just be links

so the answer should be:



-- 
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/1c2e59f8-9850-415b-947e-97eaa5cddc72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Tutorial Part 2 - Model not showing up on Django Admin

2017-02-22 Thread Dylan Reinhold
Post your admin.py file and make sure that admin.py file is in your app
folder.

For #3, when you added your app and ran makemigrations it should have built
a migration file for any of your models in model.py.


On Wed, Feb 22, 2017 at 1:20 PM, t0mgs  wrote:

> Hi there,
>
> This is my first time inside a mailing list. Oh, the jitters! :)
>
> Anyways, in the second part of the Django tutorial
> 
>  there's
> a section in which we are to modify our `admin.py` file in order to make
> sure the Django admin site recognizes our objects and pulls them up when it
> is loaded.
>
> I'm not sure if that's a glitch in the actual tutorial, and I imagine it's
> not, but for the life of me I can't figure out the problem.
>
> I've managed to:
>
>1.
>2. 1. Registered my app in the admin.py file.
>3. 2. Added it to INSTALLED_APPS in settings.py in my project folder.
>4. 3. Ran python manage.py makemigrations & python manage.py migrate
>without any changes.
>5. 4. Made sure the user I'm signing in with has superuser priviliges
>(as per this answer).
>6. 5. Restarted my nginx.
>
>  If anyone can help, I would love to stop smashing my head against the
> wall.
>
> Tips on how to debug the admin site will also be highly appreciated.
>
> Thanks in advance!
>
> -T
>
> --
> 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/d3c8e0a3-a6f9-4d0d-8499-8db66d452110%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/CAHtg44ANzx8o6wAPnqmxaSjaNFLU%2BDOnEh1Jbh6D%2BQZvLYcPUw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django official tutorial part 2 problem - model won't show on admin site

2017-02-22 Thread t0mgs
Hi there,

I've posted another topic but it seems to have gotten lost somehow. Not 
sure if there's approval needed or something.

Anyways - I got stuck in this part of the tutorial 
,
 
and I've tried a few things to no avail - I can't seem to see the model in 
question (called Question) in my admin site:

-Registered my app in the admin.py file.
-Added it to INSTALLED_APPS in settings.py in my project folder.
-Ran python manage.py makemigrations & python manage.py migrate without any 
changes (btw, for future readers - that's the new >1.8 incarnation of 
syncdb, I believe).
-Made sure the user I'm signing in with has superuser priviliges (as per 
this answer).
-Restarted my nginx.

Thoughts?

-T

-- 
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/efeff828-13d0-469d-ab94-4515383a7240%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Routing to database based on user

2017-02-22 Thread Wilkinson Tavares
Hi Tom,
Did the solution Ansii suggested work?
Have you got some scalability problem with this solution?

On Monday, 30 January 2012 19:01:21 UTC-3, Tom Eastman wrote:
>
> Hey guys,
>
> I'm writing a django project that will require me to route queries to
> certain large databases based on who the logged in user is.
>
> So all the tables for django.contrib.auth and session and stuff will be
> in the 'central' database, as well as a table that maps users to which
> database they need to use for the main app.
>
> Can you help me come up with a way of routing database queries this way
> using a Django database router?
>
> At the start of the view could I take the logged in user from
> request.user or wherever it is, and some how provide that variable to my
> database router for the rest of the request?
>
> All suggestions welcome.
>
> Cheers!
>
> Tom
>
>

-- 
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/6ddc8f84-abc3-4454-a9b0-b58de2f9939c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Tutorial Part 2 - Model not showing up on Django Admin

2017-02-22 Thread t0mgs
Hi there,

This is my first time inside a mailing list. Oh, the jitters! :)

Anyways, in the second part of the Django tutorial 

 there's 
a section in which we are to modify our `admin.py` file in order to make 
sure the Django admin site recognizes our objects and pulls them up when it 
is loaded. 

I'm not sure if that's a glitch in the actual tutorial, and I imagine it's 
not, but for the life of me I can't figure out the problem.

I've managed to:

   1. 
   2. 1. Registered my app in the admin.py file.
   3. 2. Added it to INSTALLED_APPS in settings.py in my project folder.
   4. 3. Ran python manage.py makemigrations & python manage.py migrate 
   without any changes.
   5. 4. Made sure the user I'm signing in with has superuser priviliges 
   (as per this answer).
   6. 5. Restarted my nginx.

 If anyone can help, I would love to stop smashing my head against the wall.

Tips on how to debug the admin site will also be highly appreciated.

Thanks in advance!

-T

-- 
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/d3c8e0a3-a6f9-4d0d-8499-8db66d452110%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issues saving hex format data to binaryfield

2017-02-22 Thread ludovic coues
As you have editable = True, I assume you have read the code a bit. I
personnaly stopped reading after RegisterLookupMixin. If looking at
the code don't give you a solution, I would try to fallback to raw
SQL. That might be a skill more useful than the ability to update
BinaryField :)

2017-02-22 23:55 GMT+01:00 Brian O'Connell :
> The database is pre-existing and I'm creating a Django web interface for it.
> This object holds the 8-digit hex output of the unique mfr identifier of the
> MiFare rfids. There are remote terminals that interact with database through
> psycopg2 and have no issue with that field.
>
> I could change the format in the database and recode those devices but I'd
> rather just write the correct format to the database than go through the
> trouble of changing multiple aspects of the system. I'm approaching on that
> threshold of time spent trying to find this solution to time it would take
> to update the entire system but I would much rather prefer to know how to
> write the binaryfield in general anyways.
>
> On Wednesday, February 22, 2017 at 2:10:33 PM UTC-5, Shawn Milochik wrote:
>>
>> Why not base64 encode it and just store it in a charfield? There doesn't
>> seem to be any compelling reason to store it in binary.
>
> --
> 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/5d7b7d99-5416-4c9a-947a-10acd5fb37d0%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%2BTYi_wdSfCP32Fn084yOY4Y4XnLNQiNCUT9VLR%3DWUmm_wA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issues saving hex format data to binaryfield

2017-02-22 Thread Brian O'Connell
The database is pre-existing and I'm creating a Django web interface for 
it. This object holds the 8-digit hex output of the unique mfr identifier 
of the MiFare rfids. There are remote terminals that interact with database 
through psycopg2 and have no issue with that field. 

I could change the format in the database and recode those devices but I'd 
rather just write the correct format to the database than go through the 
trouble of changing multiple aspects of the system. I'm approaching on that 
threshold of time spent trying to find this solution to time it would take 
to update the entire system but I would much rather prefer to know how to 
write the binaryfield in general anyways. 

On Wednesday, February 22, 2017 at 2:10:33 PM UTC-5, Shawn Milochik wrote:
>
> Why not base64 encode it and just store it in a charfield? There doesn't 
> seem to be any compelling reason to store it in binary.
>

-- 
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/5d7b7d99-5416-4c9a-947a-10acd5fb37d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issues saving hex format data to binaryfield

2017-02-22 Thread Brian O'Connell
I have the model set up as a binaryfield. The problem is I have no idea how 
to save the information to it. I can retrieve information from it easy 
enough but if I try and enter in new information, saved in the same format 
as that it returns

Here's what I have in model.py

class Users(models.Model):

rfid = models.BinaryField(editable = True, unique=True, blank=True, 
null=True)


def set_rfid(self,rfid_new):
print self.rfid # print the existing object data
try:
self.rfid = bytearray(rfid_new)
print self.rfid
except Exception as ex:
template = "An exception of type {0} occured. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
print message

It doesn't raise an exception but it also doesn't save it into the field. 
This is the print out (Standard PostgreSQL escape format):

E\xa343c5ea

E\x52577ade


Any help would be appreciated. 


Thanks,

Brian

On Wednesday, February 22, 2017 at 2:19:14 PM UTC-5, ludovic coues wrote:
>
> Can't you use django's BinaryField ? 
>
> 2017-02-22 20:09 GMT+01:00 Shawn Milochik  >: 
> > Why not base64 encode it and just store it in a charfield? There doesn't 
> > seem to be any compelling reason to store it in binary. 
> > 
> > -- 
> > 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/CAOzwKwG9WD2g4nvjpnbA1Y%2BuKxLmShz%3D3woTAKG%2B3VvQroWs0g%40mail.gmail.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/df8f2577-d475-4584-b970-9dade08449a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issues saving hex format data to binaryfield

2017-02-22 Thread ludovic coues
Can't you use django's BinaryField ?

2017-02-22 20:09 GMT+01:00 Shawn Milochik :
> Why not base64 encode it and just store it in a charfield? There doesn't
> seem to be any compelling reason to store it in binary.
>
> --
> 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/CAOzwKwG9WD2g4nvjpnbA1Y%2BuKxLmShz%3D3woTAKG%2B3VvQroWs0g%40mail.gmail.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%2BTZNmjWGFDSEJicK5y7Ucj07vyEQ20%3DgT5i6LFkN47i6Ag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issues saving hex format data to binaryfield

2017-02-22 Thread Shawn Milochik
Why not base64 encode it and just store it in a charfield? There doesn't
seem to be any compelling reason to store it in binary.

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


Re: Using Django Channels to subscribe to a Redis channel

2017-02-22 Thread Andrew Godwin
Hi Jochen,

Your problem is that if you want to listen to the pubsub channel you will
need a dedicated process to do so, as you can't just poll something like
that. Given that restriction, you're going to have to write something like
a management command that opens a connection to Redis and listens for
messages, and then whenever it gets one, sends the message onto a channel
in the Django channel system.

You can send to channels from anywhere, so it's just a basic listener with
one line of channel send added. You're likely to want some sort of logic on
these messages, I suspect, so I would send onto a single custom channel and
then, now your messages are in the evented channel system, you can then
write a consumer for that channel and tie it into the routing and handle
any distribution/storage there.

This keeps the body of your logic inside the Django consumer code, and the
management command nice and simple - it just needs to send onto a custom
channel and not worry about what to do with that data, you can hook that up
later. If you have fields in the message you split out into different
dictionary keys, you can even use the Channels routing options on those
fields - so, for example, you could route everything with a certain task
name to one consumer, and everything else to a catch-all consumer.

Andrew

On Wed, Feb 22, 2017 at 6:55 AM, Jochen Breuer  wrote:

> Hi!
>
> I'm not entirely sure where to start and I hope you can help me. I'm using
> SaltStack to execute tasks on minions. The results of those jobs (that's
> the term used in Salt) are then published to a job cache. In this case its
> a Redis server (Redis Pubsub). Now I would like to subscribe to a specific
> Redis channel, where the job results are published, with my Django
> (Channels) application. Every time a job result is pushed, I'd also like to
> push a message to a channel in Django.
>
> Where to begin? Do I need to write a new protocol server or just a custom
> channel? Even after reading the docs I'm still lacking overview. Perhaps
> someone can push me into the right direction. Thanks!
>
> Jochen
>
> --
> 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/c933a5b5-7b72-4d7d-985a-a311c0f16b26%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/CAFwN1urw99qQb7%2BigCFCF1m3H33Cjxuw-_-6Aw82wc%3DDjLtR5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models/Foreign Keys best practice

2017-02-22 Thread Richard Jackson
Hi Melvyn - great reply, thank you so much for taking the time to help! 
I've got to head out now but will reply tomorrow - just wanted to leave an 
initial thank you note!

Rich



On Wednesday, February 22, 2017 at 5:01:36 PM UTC, Melvyn Sopacua wrote:
>
> Hi Richard,
>
>  
>
> good questions and your initial data model defines your application 
> challenges. It is by far the most important step in application design, so 
> it's important to get it "as right as possible".
>
>  
>
> On Wednesday 22 February 2017 06:25:24 Richard Jackson wrote:
>
>  
>
> > The app lists performances, who's performing, what my role is with
>
> > them (i.e. conductor, pianist etc.), the venue and the start
>
> > date/time of these performances.
>
>  
>
> I come up with these separate entities:
>
> - Performance (or "Show" or "Series")
>
> - Ensemble
>
> - Role within Ensemble
>
> - Venue
>
> - Event: performance using a certain Ensemble, playing a Role at a certain 
> date
>
>  
>
> Date is a bad class name to use for a variety of reasons, but also doesn't 
> cover the load. Event does.
>
>  
>
> Now you can see the links clearly:
>
> - Role: Ensemble
>
> - Event: Ensemble, Role, Performance
>
>  
>
> The questions to answer is: Within each ensemble can you switch roles? If 
> so, they don't need to be linked and Event will link them
>
>  
>
> In fact, it's probably best not to link them, as you can always enforce 
> this in logic.
>
>  
>
> A more general remark:
>
> While you're free to use the class name as the field name, most of us will 
> use "name", "title" or "designation" if you're Borg minded, for the field 
> name. So Role.role becomes Role.name.
>
>  
>
> Results:
>
>  
>
> > class Performance(models.Model):
>
> > """First attempt at a thing!"""
>
> > performance_name = models.CharField(max_length=200)
>
> > link = models.CharField(max_length=200)
>
> > 
>
> > def __unicode__(self):
>
> > return self.performance_name
>
> > 
>
> > 
>
> > class Ensemble(models.Model):
>
> > performance = models.ForeignKey(Performance)
>
>  
>
> No key here
>
>  
>
> > ensemble = models.CharField(max_length=200)
>
> > 
>
> > def __unicode__(self):
>
> > return self.ensemble
>
> > 
>
> > 
>
> > class Role(models.Model):
>
> > performance = models.ForeignKey(Performance)
>
>  
>
> No key here
>
>  
>
> > role = models.CharField(max_length=200)
>
> > 
>
> > def __unicode__(self):
>
> > return self.role
>
> > 
>
> > 
>
> > class Venue(models.Model):
>
> > performance = models.ForeignKey(Performance)
>
>  
>
> No key here. This is just the place. It should be possible to do two 
> different performances at the same venue, without having to create two 
> venues.
>
>  
>
> > venue = models.CharField(max_length=200)
>
> > 
>
> > def __unicode__(self):
>
> > return self.venue
>
> > 
>
> > 
>
> > class Date(models.Model):
>
>  
>
> Event
>
>  
>
> > performance = models.ForeignKey(Performance)
>
> ensemble = models.ForeignKey(Ensemble)
>
> role = models.ForeignKey(Role)
>
> venue = models.ForeignKey(Venue)
>
>  
>
> > start_date = models.DateTimeField('Start Date',
>
> > default=timezone.now)
>
>  
>
> I would use "start" or start_time since it's not just a date.
>
>  
>
> > end_date = models.DateTimeField('End Date',
>
> > default=timezone.now)
>
>  
>
> I would use duration = models.DurationField 
> 
> ()
>
>  
>
>  
>
> Now, if you look at "Event", it contains foreign keys to models that only 
> have a charfield. So, it makes sense to simply make those CharFields.
>
> But...a Venue, has an address. An Ensemble has members and you may get 
> different but fixed wages for each role. These are reasons to use Foreign 
> Keys. Otherwise, just use a CharField.
>
>  
>
> If you don't need to record anything special about roles, there's also the 
> middle ground using a field's choices 
> . You 
> use choices instead of a Foreign Key if they hardly ever change and don't 
> need to be managed in the Admin.
>
>  
>
> Hope this helps.
>
> -- 
>
> Melvyn Sopacua
>

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


Issues saving hex format data to binaryfield

2017-02-22 Thread Brian O'Connell
I have a project where I am saving RFID information (which comes in as hex 
strings) to a bytea object in my postgres database. I can retrieve this 
information without issue. I am struggling to overwrite that object with 
new data (For when someone loses their rfid and needs to replace it). I 
have been unable to find an example of someone saving a small amount of 
data to a binaryfield. Just lots of people saying don't save images or 
files to binary fields and then explaining how to do that. 

Can anyone help me with simply saving something to a binaryfield to update 
a bytea object in a PostgreSQL database?

Thanks,
Brian

-- 
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/8a21790a-1fec-49ad-a3c2-c16865022abf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "Ask the Django Team Anything" IRC session - Wed Feb 22 18:00 UTC

2017-02-22 Thread Tim Graham
This is starting in about 30 minutes. Any Django team members who want to 
participate in the question answering, please ping me on IRC.

On Monday, February 20, 2017 at 9:02:38 AM UTC-5, Tim Graham wrote:
>
> In partnership with the freenode community team, the Django team will hold 
> an "Ask Me Anything" session this week.
>
> See http://freenode.net/news/django-ama for details.
>

-- 
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/0e6adf0e-b396-44e2-8507-424ae3611621%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models/Foreign Keys best practice

2017-02-22 Thread Melvyn Sopacua
Hi Richard,

good questions and your initial data model defines your application challenges. 
It is 
by far the most important step in application design, so it's important to get 
it "as 
right as possible".

On Wednesday 22 February 2017 06:25:24 Richard Jackson wrote:

> The app lists performances, who's performing, what my role is with
> them (i.e. conductor, pianist etc.), the venue and the start
> date/time of these performances.

I come up with these separate entities:
- Performance (or "Show" or "Series")
- Ensemble
- Role within Ensemble
- Venue
- Event: performance using a certain Ensemble, playing a Role at a certain date

Date is a bad class name to use for a variety of reasons, but also doesn't 
cover the 
load. Event does.

Now you can see the links clearly:
- Role: Ensemble
- Event: Ensemble, Role, Performance

The questions to answer is: Within each ensemble can you switch roles? If so, 
they 
don't need to be linked and Event will link them

In fact, it's probably best not to link them, as you can always enforce this in 
logic.

A more general remark:
While you're free to use the class name as the field name, most of us will use 
"name", 
"title" or "designation" if you're Borg minded, for the field name. So 
Role.role becomes 
Role.name.

Results:

> class Performance(models.Model):
> """First attempt at a thing!"""
> performance_name = models.CharField(max_length=200)
> link = models.CharField(max_length=200)
> 
> def __unicode__(self):
> return self.performance_name
> 
> 
> class Ensemble(models.Model):
> performance = models.ForeignKey(Performance)

No key here

> ensemble = models.CharField(max_length=200)
> 
> def __unicode__(self):
> return self.ensemble
> 
> 
> class Role(models.Model):
> performance = models.ForeignKey(Performance)

No key here

> role = models.CharField(max_length=200)
> 
> def __unicode__(self):
> return self.role
> 
> 
> class Venue(models.Model):
> performance = models.ForeignKey(Performance)

No key here. This is just the place. It should be possible to do two different 
performances at the same venue, without having to create two venues.

> venue = models.CharField(max_length=200)
> 
> def __unicode__(self):
> return self.venue
> 
> 
> class Date(models.Model):

Event

> performance = models.ForeignKey(Performance)
ensemble = models.ForeignKey(Ensemble)
role = models.ForeignKey(Role)
venue = models.ForeignKey(Venue)

> start_date = models.DateTimeField('Start Date',
> default=timezone.now)

I would use "start" or start_time since it's not just a date.

> end_date = models.DateTimeField('End Date',
> default=timezone.now)

I would use duration = models.DurationField[1]()


Now, if you look at "Event", it contains foreign keys to models that only have 
a 
charfield. So, it makes sense to simply make those CharFields.
But...a Venue, has an address. An Ensemble has members and you may get 
different 
but fixed wages for each role. These are reasons to use Foreign Keys. 
Otherwise, just 
use a CharField.

If you don't need to record anything special about roles, there's also the 
middle 
ground using a field's choices[2]. You use choices instead of a Foreign Key if 
they 
hardly ever change and don't need to be managed in the Admin.

Hope this helps.
-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/1.10/ref/models/fields/#durationfield
[2] https://docs.djangoproject.com/en/1.10/ref/models/fields/#choices

-- 
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/1761837.TQ8NGH0QgD%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Bug? django.contrib.auth.forms using User model by importing from auth.models instead of get_user_model()

2017-02-22 Thread Davor Lučić
Fair enough, I guess subclassing it makes more sense, I saw that it uses
`USERNAME_FIELD`[1] so I assumed it could use the custom model by default
too, but I guess you can have completely different models and that could
create some confusion.

Anyway, sorry to take you time and thanks for quick response,
Cheers!

1:
https://github.com/django/django/blob/master/django/contrib/auth/forms.py#L92


On 22 February 2017 at 17:05, Davor Lučić  wrote:

> Hello,
>
> I have issues using custom user model and forms from contrib.auth.forms
> When using `UserCreationForm` it says `auth_user table does not exists`
> which is expected since i have different user model.
>
> Looking at the code, some pieces of code use `get_user_model` and
> `UserModel` while model forms use `User` imported from `auth.models`.
>
> For example:
>
> https://github.com/django/django/blob/master/django/
> contrib/auth/forms.py#L10
> https://github.com/django/django/blob/master/django/
> contrib/auth/forms.py#L86
>
> If i use UserModel there it seems to work fine. Would this be considered a
> bug?
> Just wanted to check before creating a ticket.
>
> Thank you,
> Davor
>
>
>

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


Re: A server that runs django

2017-02-22 Thread Tim Graham
Nope, there's nothing wrong with using nginx and Django.

On Wednesday, February 22, 2017 at 10:53:45 AM UTC-5, Luvpreet Singh wrote:
>
> Yeah I am running my django on nginx. I just wanted to make sure that if 
> I'm doing wrong by doing so?
>
>
> On Tuesday, February 7, 2017 at 1:08:01 AM UTC+5:30, Dário Carvalho wrote:
>>
>> Hi everyone. So, I now understand a little more about how django works 
>> and I was thinking about how can I run a site built with django in my own 
>> python's server.
>> Someone know how can I do such thing? I thought about using asyncio 
>> and/or socketserver or even http with socketserver. Anyway, 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/06926541-da8c-4060-988c-e1bb723c9359%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Bug? django.contrib.auth.forms using User model by importing from auth.models instead of get_user_model()

2017-02-22 Thread Tim Graham
The documentation says you need to rewrite UserCreationForm for a custom 
user model: 
https://docs.djangoproject.com/en/stable/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms.

On Wednesday, February 22, 2017 at 11:06:14 AM UTC-5, rebus wrote:
>
> Hello,
>
> I have issues using custom user model and forms from contrib.auth.forms
> When using `UserCreationForm` it says `auth_user table does not exists` 
> which is expected since i have different user model.
>
> Looking at the code, some pieces of code use `get_user_model` and 
> `UserModel` while model forms use `User` imported from `auth.models`.
>
> For example:
>
>
> https://github.com/django/django/blob/master/django/contrib/auth/forms.py#L10
>
> https://github.com/django/django/blob/master/django/contrib/auth/forms.py#L86
>
> If i use UserModel there it seems to work fine. Would this be considered a 
> bug? 
> Just wanted to check before creating a ticket.
>
> Thank you,
> Davor
>
>
>

-- 
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/26176582-7591-4882-9c9e-bc44d91fae5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Bug? django.contrib.auth.forms using User model by importing from auth.models instead of get_user_model()

2017-02-22 Thread Davor Lučić
Hello,

I have issues using custom user model and forms from contrib.auth.forms
When using `UserCreationForm` it says `auth_user table does not exists`
which is expected since i have different user model.

Looking at the code, some pieces of code use `get_user_model` and
`UserModel` while model forms use `User` imported from `auth.models`.

For example:

https://github.com/django/django/blob/master/django/contrib/auth/forms.py#L10
https://github.com/django/django/blob/master/django/contrib/auth/forms.py#L86

If i use UserModel there it seems to work fine. Would this be considered a
bug?
Just wanted to check before creating a ticket.

Thank you,
Davor

-- 
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/CAKB_9CJDg-J0bkvCy0O%3DOpA0pAkRUr7WuPE2syfK3ydx8F-vbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initial data, tests and migrations

2017-02-22 Thread Tim Graham
I'm not trying to be antagonistic, sorry if I came off that way. I wanted 
to point out the difficulties that Django encountered trying to provide 
"integration" tests like django-otp does. As others suggested, if 
django-otp provided tools to build your own integration tests, that might 
be a better way forward.

On Wednesday, February 22, 2017 at 10:14:26 AM UTC-5, Tom Evans wrote:
>
> On Wed, Feb 22, 2017 at 2:40 PM, Tim Graham  > wrote: 
> > I'm curious if you feel that running django_otp's tests as part of your 
> > project's tests is adding value. 
>
> I'm curious whether you think I commonly spend my time doing things 
> that I don't think add value... 
>
> django_otp is simply an example of this issue, but yes, running those 
> tests would give my project value. 
>
> These tests exercise parts of django_otp that interact with parts of 
> my code. Successful tests indicate that those two parts interoperate 
> correctly. The tests are successful when run individually, but fail 
> when run as a suite because data loaded as part of a migration is 
> flushed away before the second test. 
>

-- 
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/751918fc-a96f-469b-bd3e-b19a10adf15a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A server that runs django

2017-02-22 Thread Luvpreet Singh
Yeah I am running my django on nginx. I just wanted to make sure that if 
I'm doing wrong by doing so?


On Tuesday, February 7, 2017 at 1:08:01 AM UTC+5:30, Dário Carvalho wrote:
>
> Hi everyone. So, I now understand a little more about how django works and 
> I was thinking about how can I run a site built with django in my own 
> python's server.
> Someone know how can I do such thing? I thought about using asyncio and/or 
> socketserver or even http with socketserver. Anyway, 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/d50fffbb-df42-4287-82ad-5e9175ea2967%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A server that runs django

2017-02-22 Thread Tim Graham
Sure, do a web search for "nginx django" to find instructions.

On Wednesday, February 22, 2017 at 10:41:07 AM UTC-5, Luvpreet Singh wrote:
>
> Well, I completely agree with you. But can we use Nginx servers?
>
>
> On Tuesday, February 7, 2017 at 1:08:01 AM UTC+5:30, Dário Carvalho wrote:
>>
>> Hi everyone. So, I now understand a little more about how django works 
>> and I was thinking about how can I run a site built with django in my own 
>> python's server.
>> Someone know how can I do such thing? I thought about using asyncio 
>> and/or socketserver or even http with socketserver. Anyway, 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/cf05e0cb-d9d1-4283-85d3-12e6f0caeeb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template language resolve url

2017-02-22 Thread Luvpreet Singh
Iudovic is right, your syntax is wrong.

use  {% url 'ytlinks:save_ytlinks' %}

the original syntax is ,  {% url 'namespace:url_name' arguments %}
On Thursday, February 16, 2017 at 9:42:14 PM UTC+5:30, xyron wrote:
>
> Code hier eingeben...
>
> Hey there,
>
> I'm searching since more than 12 hours for a solution for my problem and 
> I'm kinda frustrated.
>
> I want to use a form and define the link using django template language in 
> a html-file:
>
> {% extends "base/header.html" %}
> {% block content %}
>
>   
>Enter Youtube-Link
> 
>
> I get following error:
>
> Reverse for 'links.views.save_ytlink' with arguments '()' and keyword 
> arguments '{}' not found. 0 pattern(s) tried: []
>
> My project structure looks like this:
>
> mysite
> +---links
> ¦   +---templates
> ¦   ¦   +---home.html
> ¦   +---urls.py
> ¦   +---views.py 
> +---mainapp
> +---templates
> ¦   +---base
> ¦   ¦   +---header.html
> ¦   +---links
> ¦   +---register
> +---urls.py
> +---views.py
>
>
> mainapp.urls.py looks like this:
>
> urlpatterns = [
> url(r'^', include('links.urls', namespace='ytlinks'), name='index'),
> url(r'^admin/', admin.site.urls),
> url(r'^register', include('register.urls'), name='register'),
> url(r'^ytlinks/', include('links.urls', namespace='ytlinks')),
> ]
>
>
> links.urls.py looks like this:
>
> urlpatterns = [
>url(r'^save_ytlink', views.save_ytlink, name='save_ytlink'),
>url(r'^list$', views.ytlinks_list, name='ytlinks_list'),
>url(r'^', views.ytlinks, name='ytlinks'),
> ]
>
>
> links.views.py looks like this:
>
> def save_ytlink(request):
> msg = ""
> msg_status = "" # possible: 'success', 'info', 'danger', 'warning'
>
>
> # Check if user came here by form
> if request.method == 'GET':
> return render(request, 'home.html')
>
>
> ytlink = request.POST['ytlink']
> allow_save = True
>
>
> # Validation
> # ...
>
>
> return render(request, 'home.html', {'queryset':'', 'msg':msg, 
> 'msg_status':msg_status})
>
>
> Things I tried:
>
> 
> 
> 
> 
> 
>
> (and much more)
>
> I tried to set namespaces, to see if it makes any difference. Also stuff 
> with ../views.save_ytlink didn't work.
>
> Also if I create a file called "test.html" (located in the same 
> directory), it doesn't  change the error.
>
> {% url 'test.html' %}
>
> If I use:
>
> 
>
> It works.
>
> What am I doing wrong? I really, really appreciate any attempt to help.
>
> xyron
>
>
>

-- 
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/85318c8b-2e82-4076-8736-ded3da1fb96f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A server that runs django

2017-02-22 Thread Luvpreet Singh
Well, I completely agree with you. But can we use Nginx servers?


On Tuesday, February 7, 2017 at 1:08:01 AM UTC+5:30, Dário Carvalho wrote:
>
> Hi everyone. So, I now understand a little more about how django works and 
> I was thinking about how can I run a site built with django in my own 
> python's server.
> Someone know how can I do such thing? I thought about using asyncio and/or 
> socketserver or even http with socketserver. Anyway, 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/9f1fa284-b989-4690-b46a-091908c97d8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initial data, tests and migrations

2017-02-22 Thread Melvyn Sopacua
On Wednesday 22 February 2017 15:13:47 'Tom Evans' via Django users wrote:

> These tests exercise parts of django_otp that interact with parts of
> my code. Successful tests indicate that those two parts interoperate
> correctly. The tests are successful when run individually, but fail
> when run as a suite because data loaded as part of a migration is
> flushed away before the second test.

So they're different tests: they make use of the logic of the library's test 
suite, 
but operate on your data. Schoolbook example for inheritance:

from django_otp.tests import SuperTest

class SuperTestWithMyData(SuperTest):
fixtures = ['my_data']

-- 
Melvyn Sopacua

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


Re: Models/Foreign Keys best practice

2017-02-22 Thread Luvpreet Singh
Hi Richard,

I am facing a difficulty here.
Can you please tell me that how to iterate over this queryset , 
performance.ensemble_set.all()  ??

Thanks.

On Wednesday, February 22, 2017 at 7:55:24 PM UTC+5:30, Richard Jackson 
wrote:
>
> Hi all,
>
> I'm putting together my first app, closely modelled on the Django 
> tutorial, and wanted some advice regarding when to split the various models 
> into different foreign keys.
>
> The app lists performances, who's performing, what my role is with them 
> (i.e. conductor, pianist etc.), the venue and the start date/time of these 
> performances.
>
> I'd initially thought I should split these all into separate classes, 
> since, for example, the same Ensemble might be involved in a different 
> performance, but I'm now not sure that's correct (/my understanding is 
> incorrect). Would someone mind letting me know if this is a good idea or 
> whether there's a better practice I should follow.
>
> I've included my models.py file below:
>
> from django.db import models
> from django.utils import timezone
> # Create your models here.
>
>
> class Performance(models.Model):
> """First attempt at a thing!"""
> performance_name = models.CharField(max_length=200)
> link = models.CharField(max_length=200)
>
> def __unicode__(self):
> return self.performance_name
>
>
> class Ensemble(models.Model):
> performance = models.ForeignKey(Performance)
> ensemble = models.CharField(max_length=200)
>
> def __unicode__(self):
> return self.ensemble
>
>
> class Role(models.Model):
> performance = models.ForeignKey(Performance)
> role = models.CharField(max_length=200)
>
> def __unicode__(self):
> return self.role
>
>
> class Venue(models.Model):
> performance = models.ForeignKey(Performance)
> venue = models.CharField(max_length=200)
>
> def __unicode__(self):
> return self.venue
>
>
> class Date(models.Model):
> performance = models.ForeignKey(Performance)
> start_date = models.DateTimeField('Start Date', default=timezone.now)
> end_date = models.DateTimeField('End Date', default=timezone.now)
>
>
> Thanks!
>
> Rich
>

-- 
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/d998078b-dd87-43a6-ac6c-1cb5b120f135%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initial data, tests and migrations

2017-02-22 Thread Adam Stein
On Wed, 2017-02-22 at 15:06 +, 'Tom Evans' via Django users wrote:
> On Wed, Feb 22, 2017 at 2:41 PM, Adam Stein  wrote:
> > 
> > On Wed, 2017-02-22 at 14:22 +, 'Tom Evans' via Django users
> > wrote:
> > 
> > The URL you refer to mentions about loading data for apps. Doesn't
> > mention
> > anything in regards to tests. Why are fixtures bad for tests? In
> > fact, right
> > above the "Providing initial data with migrations" section is a
> > "See also"
> > box that says "Fixtures are also used by the testing framework to
> > help set
> > up a consistent test environment". It would seem to me that the
> > docs are
> > telling you to use fixtures for tests and use migrations for real
> > data.
> OK. How do I load that data from a fixture in a TestCase I cannot
> modify?
Unfortunately, nothing easy comes to mind. My only thought was the
possibility of putting your own wrapper around their tests. The idea
being is that you call your wrapper which in turns loads the fixtures
and calls their tests rather than having Django call their tests
directly. This wrapper could be a unit test or be a derivative of the
Django test runner. Don't know how feasible either is but I'm guessing
neither would be trivial. Maybe I'm wrong, I didn't pursue the thought
any more than having a wrapper of some kind.
I was originally just going on your statements that fixtures weren't
used in the tests because they weren't recommended (which is not really
the case). Hope you figure something out.
> Cheers
> 
> Tom
> 
> 

-- 
Adam (a...@csh.rit.edu)


-- 
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/1487776952.29637.10.camel%40csh.rit.edu.
For more options, visit https://groups.google.com/d/optout.


Re: Initial data, tests and migrations

2017-02-22 Thread Melvyn Sopacua
On Wednesday 22 February 2017 14:22:36 'Tom Evans' via Django users wrote:
> On Wed, Feb 22, 2017 at 12:47 AM, Melvyn Sopacua  
wrote:
> > On Tuesday 21 February 2017 19:00:42 'Tom Evans' via Django users wrote:

> >> What is the "correct" way of ensuring that these instances exist in
> >> 
> >> the test database before any test is run?
> > 
> > All explained in the docs.
> > 
> > Either redeclare the same fixtures for different test cases or
> > reorganize your testcases to share the same fixture(s).
> 
> I think you have misunderstood:
> 
> 1) The test cases belong to a library and cannot be modified

So don't use them as is or prompt the authors to update to the new way of 
things. In 
transition, you can extend the test cases and simply add a fixture attribute.

> 2) The initial data is populated from a data migration and not from a
> fixture, as that is not recommended [1]

Data migrations for the project are never relevant for tests, since the test 
database is 
empty. You're putting a label on "fixtures" that is only relevant for the 
provided context. 
Fixtures are not deprecated, not bad for you and do not mess up your aura.
On one hand It is as Adam says:
" It would seem to me that the docs are telling you to use fixtures for tests 
and use 
migrations for real data."

Adding to that - fixtures are still a solid way to load application data - only 
the use of 
"initial" or "autloaded" data is discouraged.
Fixtures should be used on production databases to selectively provide data, so 
that 
the user of the application can load "google_shopping.json" if it wants to 
publish it's 
products Google Shopping or not load it, if she doesn't.

-- 
Melvyn Sopacua

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


Re: Initial data, tests and migrations

2017-02-22 Thread 'Tom Evans' via Django users
On Wed, Feb 22, 2017 at 2:40 PM, Tim Graham  wrote:
> I'm curious if you feel that running django_otp's tests as part of your
> project's tests is adding value.

I'm curious whether you think I commonly spend my time doing things
that I don't think add value...

django_otp is simply an example of this issue, but yes, running those
tests would give my project value.

These tests exercise parts of django_otp that interact with parts of
my code. Successful tests indicate that those two parts interoperate
correctly. The tests are successful when run individually, but fail
when run as a suite because data loaded as part of a migration is
flushed away before the second test.

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


Re: Initial data, tests and migrations

2017-02-22 Thread 'Tom Evans' via Django users
On Wed, Feb 22, 2017 at 2:41 PM, Adam Stein  wrote:
> On Wed, 2017-02-22 at 14:22 +, 'Tom Evans' via Django users wrote:
>
> The URL you refer to mentions about loading data for apps. Doesn't mention
> anything in regards to tests. Why are fixtures bad for tests? In fact, right
> above the "Providing initial data with migrations" section is a "See also"
> box that says "Fixtures are also used by the testing framework to help set
> up a consistent test environment". It would seem to me that the docs are
> telling you to use fixtures for tests and use migrations for real data.

OK. How do I load that data from a fixture in a TestCase I cannot modify?

Cheers

Tom

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


Using Django Channels to subscribe to a Redis channel

2017-02-22 Thread Jochen Breuer
Hi!

I'm not entirely sure where to start and I hope you can help me. I'm using 
SaltStack to execute tasks on minions. The results of those jobs (that's 
the term used in Salt) are then published to a job cache. In this case its 
a Redis server (Redis Pubsub). Now I would like to subscribe to a specific 
Redis channel, where the job results are published, with my Django 
(Channels) application. Every time a job result is pushed, I'd also like to 
push a message to a channel in Django.

Where to begin? Do I need to write a new protocol server or just a custom 
channel? Even after reading the docs I'm still lacking overview. Perhaps 
someone can push me into the right direction. Thanks!

Jochen

-- 
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/c933a5b5-7b72-4d7d-985a-a311c0f16b26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initial data, tests and migrations

2017-02-22 Thread Tim Graham
I'm curious if you feel that running django_otp's tests as part of your 
project's tests is adding value. All third-party apps that I've used 
(including tests for django.contrib apps*) have moved their tests to a 
separate directory so that they're not installed along with the 
application. It's quite difficult for a library to write tests that work 
with whatever settings a project might provide -- at least that's what we 
found with tests for contrib apps.

* https://groups.google.com/d/topic/django-developers/nj_Zha341pA/discussion

On Wednesday, February 22, 2017 at 9:23:25 AM UTC-5, Tom Evans wrote:
>
> On Wed, Feb 22, 2017 at 12:47 AM, Melvyn Sopacua  > wrote: 
> > On Tuesday 21 February 2017 19:00:42 'Tom Evans' via Django users wrote: 
> > 
> > 
> > 
> >> Previously, these instances were loaded from a JSON fixtures file, 
> > 
> > 
> > 
> > And you can still do that. 
> > 
> > 
> > 
> >> which used to be the recommended way. For our own tests, we simply 
> > 
> >> load these fixtures in the setUp portion of the test; obviously we 
> > 
> >> can't go around modifying tests in third party libraries. 
> > 
> >> I tried taking them out of the fixtures, and adding them instead in a 
> > 
> >> data migration, but this also had the same effect - the instances were 
> > 
> >> there for the first test ran, and then missing for all the subsequent 
> > 
> >> ones. 
> > 
> > 
> > 
> > setUp is run between test methods of a test case. setupTestData is a 
> class 
> > method on the testcase run once per test case. 
> > 
> >> 
> > 
> >> 
> > 
> >> What is the "correct" way of ensuring that these instances exist in 
> > 
> >> the test database before any test is run? 
> > 
> > 
> > 
> > All explained in the docs. 
> > 
> > Either redeclare the same fixtures for different test cases or 
> reorganize 
> > your testcases to share the same fixture(s). 
> > 
>
> I think you have misunderstood: 
>
> 1) The test cases belong to a library and cannot be modified 
> 2) The initial data is populated from a data migration and not from a 
> fixture, as that is not recommended [1] 
>
> Data is placed in to the test database using migrations, but after the 
> first test has been run the data is flushed out again, causing the 
> second test to fail. 
> I would like the all the tests to pass: 
>   * I don't want to put the same data into fixtures as well as migrations 
> (DRY) 
>   * I don't want to modify the 3rd party library. 
>
> How? 
>
> Cheers 
>
> Tom 
>
> [1] 
> https://docs.djangoproject.com/en/1.10/howto/initial-data/#providing-initial-data-with-migrations
>  
>

-- 
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/7d58066c-79fb-451a-9369-abf86101ccfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initial data, tests and migrations

2017-02-22 Thread Adam Stein
On Wed, 2017-02-22 at 14:22 +, 'Tom Evans' via Django users wrote:
> On Wed, Feb 22, 2017 at 12:47 AM, Melvyn Sopacua 
> om> wrote:
> > 
> > On Tuesday 21 February 2017 19:00:42 'Tom Evans' via Django users
> > wrote:
> > 
> > 
> > 
> > > 
> > > Previously, these instances were loaded from a JSON fixtures
> > > file,
> > 
> > 
> > And you can still do that.
> > 
> > 
> > 
> > > 
> > > which used to be the recommended way. For our own tests, we
> > > simply
> > > 
> > > load these fixtures in the setUp portion of the test; obviously
> > > we
> > > 
> > > can't go around modifying tests in third party libraries.
> > > 
> > > I tried taking them out of the fixtures, and adding them instead
> > > in a
> > > 
> > > data migration, but this also had the same effect - the instances
> > > were
> > > 
> > > there for the first test ran, and then missing for all the
> > > subsequent
> > > 
> > > ones.
> > 
> > 
> > setUp is run between test methods of a test case. setupTestData is
> > a class
> > method on the testcase run once per test case.
> > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > What is the "correct" way of ensuring that these instances exist
> > > in
> > > 
> > > the test database before any test is run?
> > 
> > 
> > All explained in the docs.
> > 
> > Either redeclare the same fixtures for different test cases or
> > reorganize
> > your testcases to share the same fixture(s).
> > 
> I think you have misunderstood:
> 
> 1) The test cases belong to a library and cannot be modified
> 2) The initial data is populated from a data migration and not from a
> fixture, as that is not recommended [1]
> 
> Data is placed in to the test database using migrations, but after
> the
> first test has been run the data is flushed out again, causing the
> second test to fail.
> I would like the all the tests to pass:
>   * I don't want to put the same data into fixtures as well as
> migrations (DRY)
>   * I don't want to modify the 3rd party library.
> 
> How?
> 
> Cheers
> 
> Tom
> 
> [1] https://docs.djangoproject.com/en/1.10/howto/initial-data/#provid
> ing-initial-data-with-migrations
> 
The URL you refer to mentions about loading data for apps. Doesn't
mention anything in regards to tests. Why are fixtures bad for tests?
In fact, right above the "Providing initial data with migrations"
section is a "See also" box that says "Fixtures are also used by the
testing framework to help set up a consistent test environment". It
would seem to me that the docs are telling you to use fixtures for
tests and use migrations for real data.

-- 
Adam (a...@csh.rit.edu)


-- 
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/1487774504.29637.5.camel%40csh.rit.edu.
For more options, visit https://groups.google.com/d/optout.


Models/Foreign Keys best practice

2017-02-22 Thread Richard Jackson
Hi all,

I'm putting together my first app, closely modelled on the Django tutorial, 
and wanted some advice regarding when to split the various models into 
different foreign keys.

The app lists performances, who's performing, what my role is with them 
(i.e. conductor, pianist etc.), the venue and the start date/time of these 
performances.

I'd initially thought I should split these all into separate classes, 
since, for example, the same Ensemble might be involved in a different 
performance, but I'm now not sure that's correct (/my understanding is 
incorrect). Would someone mind letting me know if this is a good idea or 
whether there's a better practice I should follow.

I've included my models.py file below:

from django.db import models
from django.utils import timezone
# Create your models here.


class Performance(models.Model):
"""First attempt at a thing!"""
performance_name = models.CharField(max_length=200)
link = models.CharField(max_length=200)

def __unicode__(self):
return self.performance_name


class Ensemble(models.Model):
performance = models.ForeignKey(Performance)
ensemble = models.CharField(max_length=200)

def __unicode__(self):
return self.ensemble


class Role(models.Model):
performance = models.ForeignKey(Performance)
role = models.CharField(max_length=200)

def __unicode__(self):
return self.role


class Venue(models.Model):
performance = models.ForeignKey(Performance)
venue = models.CharField(max_length=200)

def __unicode__(self):
return self.venue


class Date(models.Model):
performance = models.ForeignKey(Performance)
start_date = models.DateTimeField('Start Date', default=timezone.now)
end_date = models.DateTimeField('End Date', default=timezone.now)


Thanks!

Rich

-- 
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/b3d1402b-6a70-4538-a0ef-3e895cf7a51e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Initial data, tests and migrations

2017-02-22 Thread 'Tom Evans' via Django users
On Wed, Feb 22, 2017 at 12:47 AM, Melvyn Sopacua  wrote:
> On Tuesday 21 February 2017 19:00:42 'Tom Evans' via Django users wrote:
>
>
>
>> Previously, these instances were loaded from a JSON fixtures file,
>
>
>
> And you can still do that.
>
>
>
>> which used to be the recommended way. For our own tests, we simply
>
>> load these fixtures in the setUp portion of the test; obviously we
>
>> can't go around modifying tests in third party libraries.
>
>> I tried taking them out of the fixtures, and adding them instead in a
>
>> data migration, but this also had the same effect - the instances were
>
>> there for the first test ran, and then missing for all the subsequent
>
>> ones.
>
>
>
> setUp is run between test methods of a test case. setupTestData is a class
> method on the testcase run once per test case.
>
>>
>
>>
>
>> What is the "correct" way of ensuring that these instances exist in
>
>> the test database before any test is run?
>
>
>
> All explained in the docs.
>
> Either redeclare the same fixtures for different test cases or reorganize
> your testcases to share the same fixture(s).
>

I think you have misunderstood:

1) The test cases belong to a library and cannot be modified
2) The initial data is populated from a data migration and not from a
fixture, as that is not recommended [1]

Data is placed in to the test database using migrations, but after the
first test has been run the data is flushed out again, causing the
second test to fail.
I would like the all the tests to pass:
  * I don't want to put the same data into fixtures as well as migrations (DRY)
  * I don't want to modify the 3rd party library.

How?

Cheers

Tom

[1] 
https://docs.djangoproject.com/en/1.10/howto/initial-data/#providing-initial-data-with-migrations

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


RE: Looking for Django tutorial that illustrates master/detail data models

2017-02-22 Thread Matthew Pava
I recommend taking a look at Formsets and, in particular, Inline Formsets.
The documentation:
ModelForms: https://docs.djangoproject.com/en/1.10/topics/forms/modelforms/
ModelFormsets: 
https://docs.djangoproject.com/en/1.10/topics/forms/modelforms/#model-formsets
InlineFormsets: 
https://docs.djangoproject.com/en/1.10/topics/forms/modelforms/#inline-formsets

The API documentation:
https://docs.djangoproject.com/en/1.10/ref/forms/models/
https://docs.djangoproject.com/en/1.10/ref/forms/models/#inlineformset-factory

You may want to use something like Django dynamic forms on the frontend to 
utilize JavaScript.
https://github.com/elo80ka/django-dynamic-formset



From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Axil-Mar Imam
Sent: Tuesday, February 21, 2017 7:00 PM
To: Django users
Subject: Re: Looking for Django tutorial that illustrates master/detail data 
models

Hi. I wondering if you have found a way about your problem? Im actually 
researching on this problem as well, unfortunately, haven't found a solution to 
this. If you have, I would really appreciate if you share it. Thanks.

On Wednesday, December 31, 2008 at 10:44:57 AM UTC+8, ldm999 wrote:
Thanks for your response.

I should have been more clear. I'm looking for examples of views/forms
to manage the children of a parent child model. Eg how to add/change/
delete a book on a book list.

I don't recall the Django tutorial covering this and I just looked
again. It appears to focus more on the Django Admin than on custom
forms. And what it does cover wrt forms seems mostly focused on a form
for a stand-alone model rather than the child of a prent model where
you need the context of the parent to make sure you add a new item to
the right parent, and edit/delete the correct item based on its
parent.

I'll take another detailed look at the official tutorial to see if
this is covered.

On Dec 30, 6:02 pm, Daniel Roseman 
>
wrote:
> On Dec 30, 8:22 pm, ldm999 
> > wrote:
>
> > Eg:
> > Lists (books, movies, restaurants) and multiple items per list.
>
> > Web forms would allow user to:
> > - Add/change/delete lists
> > - Add/change/delete list items
>
> > TIA
>
> Have you actually read the tutorial on the Django site? The Poll
> application covers exactly this.
> --
> DR.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com.
To post to this group, send email to 
django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9e3e6e5a-729c-46ab-aa12-b73207a0d88b%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/6e751ae3b2984b77bc7f1ec44c44ea87%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Is this possible with Django, new to this!

2017-02-22 Thread Melvyn Sopacua
Hi,

Being modern is hardly ever a good reason to undertake a project and it shows 
in how 
you set your requirements.
If however:
 *  You have time to spare and want to learn how to create a web application
 *  Requirement of the project is that everyone should always have access 
to the 
latest information, if they have an internet connection
 *  You or your company wants to move away from desktop to internet and 
have 
allocated ample resources to transition
then read on.

On Wednesday 22 February 2017 01:25:20 ushills wrote:

> Can I create a view into a database with approximately 20 fields that
> allows be to drill down into each row and that allows me to view and
> enter transactional information and view an audit path for how each
> row has changed over time.

To work with Django, think the other way around. You don't have a database, you 
have 
objects (models[1]), with attributes (fields[2]) that happened to be retrieved 
from and 
stored in[3] a database. Even though it is possible to work from database to 
model[4], 
this is really to support legacy or 3rd party databases and not the recommended 
way 
of doing things.

> Essentially, each row will be a component type with various cost
> production criteria, these will be changed over time and in
> combination produce a total cost for the completed product.

I'm actually working on that at the moment, using Component, HalfProduct and 
Product models for the catalog, and Production, Stock and Purchase affecting 
the 
costs.

> I want users to be able to enter the components, update the cost
> criteria at regular intervals and view the total cost with views into
> each component type to view the audit path of how and who has changed
> the cost criteria.

This isn't in my project requirements, so I'm only recording stock mutations. 
If I had to, 
I'd switch my custom mutations to one of these audit trail packages[5].

So in conclustion it certainly is possible, but do it for the right reasons :).
-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/1.10/topics/db/models/
[2] https://docs.djangoproject.com/en/1.10/ref/models/fields/
[3] https://docs.djangoproject.com/en/1.10/topics/db/queries/
[4] https://docs.djangoproject.com/en/1.10/ref/django-admin/#inspectdb
[5] https://djangopackages.org/grids/g/model-audit/

-- 
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/5788130.OQuhB1n9x8%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Is this possible with Django, new to this!

2017-02-22 Thread Francis Sunday
I think that is possible with Django

On Wednesday, February 22, 2017 at 1:15:15 PM UTC+1, ushills wrote:
>
> Hi, looking for some advice regarding what's possible with Django before I 
> go too far.  
>
> Can I create a view into a database with approximately 20 fields that 
> allows be to drill down into each row and that allows me to view and enter 
> transactional information and view an audit path for how each row has 
> changed over time.
>
> Essentially, each row will be a component type with various cost 
> production criteria, these will be changed over time and in combination 
> produce a total cost for the completed product.
>
> I want users to be able to enter the components, update the cost criteria 
> at regular intervals and view the total cost with views into each component 
> type to view the audit path of how and who has changed the cost criteria.
>
> I could do this as a desktop application in python, however, having it as 
> a web app seems the more modern approach, can Django do this?
>
>
>

-- 
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/42972633-62b7-4fff-9eb5-71c4b7338942%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: extend Media in custom template tag

2017-02-22 Thread guettli
 I see replies. Now I am unsure what happened:

 - nobody read my question
 - someone read it, but did not understand it
 - someone read it, understood it, but had no solution.
 - ... other.

Just for the records, here the related StackOverflow question: 
http://stackoverflow.com/questions/41592766/django-include-media-css-js-in-class-based-views

Am Montag, 9. Mai 2016 10:25:49 UTC+2 schrieb guettli:
>
> I have a custom Django template tag which creates HTML.
>
>
> This HTML needs some JS and CSS.
>
>
> How can I extend the media list with my custom template tag?
>
>
>
>
>
>

-- 
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/8270faf5-27cf-4c75-af42-8e4be7ba70a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: extend Media in custom template tag

2017-02-22 Thread guettli
I see replies. Now I am unsure what happened:

 - nobody read my question
 - someone read it, but did not understand it
 - someone read it, understood it, but had no solution.
 - ... other.


Am Montag, 9. Mai 2016 10:25:49 UTC+2 schrieb guettli:
>
> I have a custom Django template tag which creates HTML.
>
>
> This HTML needs some JS and CSS.
>
>
> How can I extend the media list with my custom template tag?
>
>
>
>
>
>

-- 
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/3bb77b31-b24d-4da2-9f9f-06b14e2306d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is this possible with Django, new to this!

2017-02-22 Thread ushills
Hi, looking for some advice regarding what's possible with Django before I 
go too far.  

Can I create a view into a database with approximately 20 fields that 
allows be to drill down into each row and that allows me to view and enter 
transactional information and view an audit path for how each row has 
changed over time.

Essentially, each row will be a component type with various cost production 
criteria, these will be changed over time and in combination produce a 
total cost for the completed product.

I want users to be able to enter the components, update the cost criteria 
at regular intervals and view the total cost with views into each component 
type to view the audit path of how and who has changed the cost criteria.

I could do this as a desktop application in python, however, having it as a 
web app seems the more modern approach, can Django do this?


-- 
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/bdfa94ce-a01f-4900-bdef-23e77f4baff2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Privacy settings like Facebook in Django.

2017-02-22 Thread Alex Richards
I want to implement privacy settings on my extended UserProfile Model where 
the user can decide who can see his field (say email for now).
The options looks something like this,

*public* - any one can view his email
*friends_of_friends* - only friends and friends of friends can view his 
email
*friends* - only his friends can view his email
*friend_list* - only a list of friends (pre defined) can view his email.

I want to implement the same for n fields in the Model (phone number, work, 
education, etc..).

I don't need code but some directions to solve it. Code examples won't 
hurt. 

-- 
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/26a3f2d8-d588-448b-8dc0-086c37a11168%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I implement a Facebook like privacy settings for extended User?

2017-02-22 Thread Alex Richards
I have an extended UserProfile to which I want to add some privacy settings 
as in Facebook. 

the options for a single field  (say email for now) should be,

*public *- any one can view his email
*friends_of_friends* - only friends and friends of friends can view his 
email
*friends *- only his friends can view his email
*friend_list* - only a list of friends (pre defined) can view his email.

The same should be applicable for other fields too (say phone, education, 
work, likes, activity etc .. ).
Can anyone guide me on the right path? I don't need code but ideas would 
help.
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/8810d747-307c-40c2-8c56-fe361ae742e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Registration form

2017-02-22 Thread RISHABH BANSAL
How can i add registration.backends.hmac,urls>
tell the complete procedure

-- 
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/df58fc52-997d-48f8-ada1-924bd1583ca7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django-channels disconnects right after sending a message

2017-02-22 Thread Nikoleta Misheva
I tried it and it works fine, but as soon as I try to hang this to a button 
it disconnects, so this line 
$('#arg_form').on('submit',function ()

is the problem, if I send message without hanging it to a button submit 
function it is ok with or without JSON.stringify

сряда, 22 февруари 2017 г., 9:27:32 UTC+2, Andrew Godwin написа:
>
> Then you need to add more and more back until it does disconnect and you 
> should be able to find the line that's doing it!
>
> Andrew
>
> On Tue, Feb 21, 2017 at 11:03 PM, Nikoleta Misheva  > wrote:
>
>> I tried  the simplest example and it works fine and does not disconnect. 
>>
>> def websocket_receive(message):
>>  text = message.content.get('text')
>>  if text:
>>  message.reply_channel.send({"text": "You said: {}".format(text)})
>>
>> And using the JS console 
>> socket = new WebSocket("ws://" + window.location.host + "/chat/");
>> socket.onmessage = function(e) {
>> alert(e.data);
>> }
>> socket.onopen = function() {
>> socket.send("hello world");
>> }
>>
>> сряда, 22 февруари 2017 г., 3:08:09 UTC+2, Andrew Godwin написа:
>>>
>>> I'm afraid I don't really know what's going on then - the logs don't 
>>> reveal very much. I'd try reducing it down to simpler code until you can 
>>> replicate it in only a few lines and work from there.
>>>
>>> Andrew
>>>
>>> On Tue, Feb 21, 2017 at 11:46 AM, Nikoleta Misheva  
>>> wrote:
>>>
 I don't know how to get the close code. It disconnects right after you 
 hit the send button but it manages to send the message, I had prints and 
 the message was right and etc but was always after disconnect. My 
 disconnect function basically deletes the room. And python's console logs:
 [2017/02/21 21:42:50] WebSocket DISCONNECT /play [127.0.0.1:65273]
 [2017/02/21 21:42:50] WebSocket HANDSHAKING /play [127.0.0.1:65282]
 It reconnects.


 вторник, 21 февруари 2017 г., 20:45:13 UTC+2, Andrew Godwin написа:
>
> How does it disconnect? What WebSocket close code do you get? (You'll 
> need to add JS to log it) What prints on the Python console?
>
> Andrew
>
> On Tue, Feb 21, 2017 at 12:27 AM, Nikoleta Misheva  
> wrote:
>
>> When I send message the websocket disconnects. I am able to get the 
>> message, but I can't proceed further since disconnect is supposed to 
>> delete 
>> the room. I tested it with basic prints after every statement and it 
>> disconnects right after the receiver gets the message because everything 
>> that is in ws_receive is printed after it disconnects
>>
>> My consumer:
>>
>> @channel_session_user
>> def ws_receive(message):
>>  username = message.user.username
>>  text = json.loads(message['text']).get('text')
>>  # Use my algorithm here
>>  score = score_argument.get_rating(text)
>>  # find the room with our users
>>  # print(type(username))
>>  # print(username)
>>  current_room = get_object_or_404(PairUsers, Q(username_a=username) | 
>> Q(username_b=username))
>>
>>  # current_room = PairUsers.objects.filter(Q(username_a=username) | 
>> Q(username_b=username)).first()
>>
>>  # check which user you got and send the message to the other
>>  if current_room.username_b == username:
>>  current_room.score_b = score
>>  other_channel = Channel(current_room.reply_channel_a)
>>  message.reply_channel.send({'text': json.dumps({
>>  "message": text,
>>  "user": username, }),
>>  })
>>  message.reply_channel.send({'text': json.dumps({
>>  "score": score,
>>  "user": username, }),
>>  })
>>  other_channel.send({'text': json.dumps({
>>  "message": text,
>>  "user": username, }),
>>  })
>>  other_channel.send({'text': json.dumps({
>>  "score": score,
>>  "user": username, }),
>>  })
>>  else:
>>  current_room.score_a = score
>>  other_channel = Channel(current_room.reply_channel_b)
>>  message.reply_channel.send({'text': json.dumps({
>>  "message": text,
>>  "user": username, }),
>>  })
>>  message.reply_channel.send({'text': json.dumps({
>>  "score": score,
>>  "user": username, }),
>>  })
>>  other_channel.send({'text': json.dumps({
>>  "message": text,
>>  "user": username, }),
>>  })
>>  other_channel.send({'text': json.dumps({
>>  "score": score,
>>  "user": username, }),
>>  })
>> The JS:
>>
>> $(function () {
>>  // Correctly decide between ws:// and wss://
>>  var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
>>  var ws_path = ws_scheme + '://' + window.location.host + 
>> window.location.pathname;
>>  console.log("Connecting to " + ws_path);
>>  var socket = new ReconnectingWebSocket(ws_path);
>>
>>  socket.onmessage = function(message){
>>  var data =