Re: bug of session middleware --- session never expires

2016-12-28 Thread Melvyn Sopacua
On Sunday 25 December 2016 18:42:16 Chaos Wong wrote:

> Thanks for the advice.
> It's indeed a rude way to force session to expire only depend on the
> absolute time. User always encounters session-expired event when
> posting something.
> I will consider your way 3). But how the django know user has closed
> the browser ?

It doesn't. The browser does.
When a cookie does not have an expiration time set, the cookie is not stored on 
disk 
but only in memory. When the browser is closed, the cookie is gone.
That means when the browser is opened again, it cannot send the session ID in 
the 
cookie anymore. This means a new session should be created (new login), and the 
old 
session should not be requested anymore and will eventually be evicted.
This also means that there will be a time window where the server session is 
valid, 
while the browser doesn't know about it anymore. So the old session *could* be 
taken 
over by someone listening on the wire. This is why encryption is paramount and 
browser now support Strict Transport Security[1].

-- 
Melvyn Sopacua


[1] 
https://github.com/ssllabs/research/wiki/SSL-and-TLS-Deployment-Best-Practices#46-deploy-http-strict-transport-security

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


Re: Subclassing Models in non model class

2016-12-28 Thread Melvyn Sopacua
On Tuesday 27 December 2016 05:51:55 M Hashmi wrote:

> I created a model Address like a normal practice below. Now I need to
> create a subclass without using models.Model. But its not letting me
> do because obviously it won't create tables unless I call
> models.Model in class parameters.
> 
> Idea is to create a model and use that model with non db reference 
in
> admin.py. Following is the code:

It's quite unclear what you want and why you want it especially. What 
does this other Address model represent?
-- 
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/5208735.ZJ1U0fmsWf%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Experiences/tips for deploying and supporting on-premise in enterprises?

2016-12-28 Thread Antonis Christofides
> For example, if you're deploying via VM, would you just go ahead and package
> Memcached in that VM, or take a different route? Similarly, have you run into
> problems using the migration framework for some enterprise clients?

If the load is small, as it seems to be, and a VM can handle it, why not just
put memcached in the VM?

I don't have much experience with enterprise clients, but why would migrations
be affected by enterpriseness? A Django site used by the customers of a small
business might be harder to migrate compared to an intranet-only enterprise
Django site, because in the first case you might not want to have any downtime
whereas in the second it might be that no-one uses it off-hours.

Antonis Christofides
http://djangodeployment.com


On 12/27/2016 08:00 PM, Todd Schiller wrote:
> Thanks - I intentionally left it vague, as I'd like to better understand the
> space of options when working with Python + Django and where headaches might
> arise. I suspect there are aspects that seem straightforward, but end up being
> a headache for certain environments.
>
> The main application is CRUD with analytics and visualization over relatively
> small data. It will have a small number of geographically diverse users. No
> scalability issues, though the application may benefit from splitting across
> geographies. Therefore, we'd be primarily looking to optimize for ease of
> deployment, integration, licensing, updating, and support. For example, we'd
> ideally have to make minimal changes to accommodate each new enterprise client
> and environment.
>
> "Hook into existing services" means whether you ended up deploying associated
> infrastructure (caching, logging, task queue) in the deployment, or whether
> you integrated into the enterprises services. For example, if you're deploying
> via VM, would you just go ahead and package Memcached in that VM, or take a
> different route? Similarly, have you run into problems using the migration
> framework for some enterprise clients?
>
> Mudassar, what in particular should I look at on that site? It looks like it's
> a service for migrate on-premise infrastructure to the cloud?
>
> On Monday, December 26, 2016 at 12:34:47 PM UTC-6, Todd Schiller wrote:
>
> My team is considering using Django for a SaaS/on-premise enterprise web
> application. We've been happy with building with Django for SaaS, but
> don't have experience deploying and supporting it on-premise in enterprise
> Linux and Windows environments. Therefore, we'd like to get the
> community's perspective before going down this path.
>
> While we appreciate all feedback, the areas we most need clarity are the
> following. For each, we'd like to hear: How did you address the area? What
> went well? What didn't go well? What do you wish you had known before
> starting?
>
>   * Deployment: e.g., direct, container, VM, or a packaging solution such
> as Replicated
>   * Integration: did you hook into existing services (caching, logging,
> etc.) or did you deploy these services alongside the application?
>   * Licensing: e.g., based on # of seats
>   * Authentication/Authorization: e.g., LDAP, AD, etc.
>   * Updates: bug fixes, and changes requiring migrations
>
> Also, if you're a development shop that has experience building enterprise
> Django applications, we'd love to chat with you because we're looking for
> some extra resources on our projects.
>
> Thanks,
> Todd
>
> -- 
> 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/a142e6e8-9781-450a-9c54-3c6469e92e7c%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/833258dc-a6e4-0700-f84e-f005d1850a9c%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Djnago project to installer

2016-12-28 Thread Melvyn Sopacua
On Monday 26 December 2016 12:45:23 Antonis Christofides wrote:
> It might be possible to install part of the stack (for example, Django
> only). It would be very difficult for the whole stack (web server,
> WSGI server, Django, database). I think it might be impossible or
> undesirable.
> 
> Why do you want this?

This is pretty much the "node" way of doing things and an untapped market for 
Django. It will probably remain untapped, while the development server remains 
deemed "not production ready" and has no "production equivalent" in behavior 
(i.e.: 
be quiet, daemonize).
There's plenty of applications that are built as a "website", and a GUI that is 
nothing 
more than a QTWebkit application window, with hidden toolbars and pointing to 
localhost:preconfigured_port.

> > I have created one web site in django.I don't want to host it,
> > instead of hosting I want to create installer of that website. Is
> > it possible with PyInstaller ? Is there any application available
> > through which we can convert django project to installer?

As outlined above, you're treading in new ground. The Django part is easy, even 
having a pre-set settings.py can be done and a pre-filled SQLite database can 
be 
shipped as well. The hard part is to fire it up and shutdown when you need it 
to.
Is this for presentation of a new website or for an stand-alone application?

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


Getting data from table with name logged in user

2016-12-28 Thread Ernst van der Heijden
Hello everyone,

I'm new to Django and have a problem. I have a table in my database with 
records that contains data for different users. All I need to do is listing 
that data with a list_view for the user that is logged in. My code now 
looks like this:

class RoosterListView(LoginRequiredMixin, ListView):
queryset = Roosters.objects.filter(startvc__range=(DatumStart, 
DatumEind),username="My_name").order_by("startvc")[:35]

For the user 'My_name' this offcourse is okay. But when I login, it should 
be 'Ernst'. So:

uname = 'Ernst'

class RoosterListView(LoginRequiredMixin, ListView):
queryset = Roosters.objects.filter(startvc__range=(DatumStart, 
DatumEind),username=uname).order_by("startvc")[:35]


This also works fine. So what I want todo is fill the variable 'uname' with 
the username from the logged in user. How do I do that. I can't get it done.

For example I tried:

from django.contrib.auth.models import User

uname = User.username

no errors but also no data.

What am I doing wrong?

Thanks in advance.
Kind regards,
Ernst

-- 
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/f8e28e62-2e4b-4513-aa97-d1aa5f7776e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Can I close the feature that django orm will create table when a modal create?

2016-12-28 Thread tinybox
Hi everyone,
I am a beginner about django. 
It seems django will create a table when the modal first create, but I 
want to create table in database by myself and forbid django creating 
table automatically. 
What can I do in setting.py?

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/76d8593f-acbd-4451-a06c-28912cf39d45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tutorial 5 (Testing) seems to have an error

2016-12-28 Thread Nicolai Bjerre Pedersen
Hi Eric,

Did you find the bug? I have the same issue running python 2.7.12 and 
django 1.10.4

Den mandag den 15. februar 2016 kl. 20.02.55 UTC+1 skrev Tim Graham:
>
> It looks like you have a Python path problem or that your project isn't 
> structured correctly such that the model is being registered twice. Does 
> that mean anything to you? I'm not sure if you are also new to Python or 
> just to Django.
>
> On Monday, February 15, 2016 at 11:16:51 AM UTC-5, Eric Livingston wrote:
>>
>> I have been walking through the Tutorial for Django, and upon reaching 
>> part 5 and introducing the first test case, I get this output (the 
>> directory I put the tutorial in is called 'demo')
>>
>>  
>>
>> RuntimeError: Model class demo.polls.models.Question doesn't declare an 
>> explicit app_label and isn't in an application in INSTALLED_APPS.
>>
>>  
>>
>> I tried adding a Meta section to the Question model, after doing some 
>> poking around in the docs.
>>
>>  
>>
>> class Question(models.Model):
>>
>> question_text = models.CharField(max_length=200)
>>
>> pub_date = models.DateTimeField('date published')
>>
>>  
>>
>> class Meta:
>>
>> app_label='polls'
>>
>>  
>>
>> But then I get this:
>>
>>  
>>
>> RuntimeError: Conflicting 'question' models in application 'polls': 
>>  and .
>>
>>  
>>
>> What modifications would I have to make to the standard Tutorial code so 
>> the Models are correctly bound to the polls app? Do I have to add something 
>> else to the installed_apps besides 'polls.apps.PollsConfig'? That's the 
>> only thing the tutorial says to add.
>>
>>  
>>
>> Thanks,
>>
>> Eric
>>
>

-- 
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/c68cc42b-733c-4f2d-b65b-40d5b878f4f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tutorial 5 (Testing) seems to have an error

2016-12-28 Thread Nicolai Bjerre Pedersen
I figured it out. I had to either delete __init__.py in my root directory 
(where manage.py is located) or call python manage.py polls.tests instead 
of just python manage.py polls

Den mandag den 15. februar 2016 kl. 20.02.55 UTC+1 skrev Tim Graham:
>
> It looks like you have a Python path problem or that your project isn't 
> structured correctly such that the model is being registered twice. Does 
> that mean anything to you? I'm not sure if you are also new to Python or 
> just to Django.
>
> On Monday, February 15, 2016 at 11:16:51 AM UTC-5, Eric Livingston wrote:
>>
>> I have been walking through the Tutorial for Django, and upon reaching 
>> part 5 and introducing the first test case, I get this output (the 
>> directory I put the tutorial in is called 'demo')
>>
>>  
>>
>> RuntimeError: Model class demo.polls.models.Question doesn't declare an 
>> explicit app_label and isn't in an application in INSTALLED_APPS.
>>
>>  
>>
>> I tried adding a Meta section to the Question model, after doing some 
>> poking around in the docs.
>>
>>  
>>
>> class Question(models.Model):
>>
>> question_text = models.CharField(max_length=200)
>>
>> pub_date = models.DateTimeField('date published')
>>
>>  
>>
>> class Meta:
>>
>> app_label='polls'
>>
>>  
>>
>> But then I get this:
>>
>>  
>>
>> RuntimeError: Conflicting 'question' models in application 'polls': 
>>  and .
>>
>>  
>>
>> What modifications would I have to make to the standard Tutorial code so 
>> the Models are correctly bound to the polls app? Do I have to add something 
>> else to the installed_apps besides 'polls.apps.PollsConfig'? That's the 
>> only thing the tutorial says to add.
>>
>>  
>>
>> Thanks,
>>
>> Eric
>>
>

-- 
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/59f9f4cf-70c4-4a84-a892-8f6629b0a841%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What determines initial number of forms in Django modelformset_factory?

2016-12-28 Thread Duane Gregory
My model formset is producing an initial 7 forms, as seen here:



I would like to alter that number, but cannot see how.
view and form for ref:

def micro_log_create(request):
MicroLogFormSet = modelformset_factory(Micro_Log, form=MicroLogForm, 
max_num=4, extra=0)
if request.method == 'POST':
formset = MicroLogFormSet(request.POST, request.FILES)
if formset.is_valid():
formset.save()
return reverse('micro-log')
else:
formset = MicroLogFormSet()
return render(request, 'app/micro_log/micro_log_create.html', 
{'formset': formset})

class MicroLogForm(forms.ModelForm):
class Meta:
model = Micro_Log   
exclude = ['user', 'date_time']
MicroLogFormSet = modelformset_factory(Micro_Log, form=MicroLogForm, 
max_num=4, extra=0)
formset = MicroLogFormSet()

Thank you

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


Re: Getting data from table with name logged in user

2016-12-28 Thread Antonis Christofides
I think what you want is self.request.user.username or something like that. At
the documentation take a look at "Request and response objects".

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 12/28/2016 10:35 AM, Ernst van der Heijden wrote:
> Hello everyone,
>
> I'm new to Django and have a problem. I have a table in my database with
> records that contains data for different users. All I need to do is listing
> that data with a list_view for the user that is logged in. My code now looks
> like this:
>
> class RoosterListView(LoginRequiredMixin, ListView):
> queryset = Roosters.objects.filter(startvc__range=(DatumStart,
> DatumEind),username="My_name").order_by("startvc")[:35]
>
> For the user 'My_name' this offcourse is okay. But when I login, it should be
> 'Ernst'. So:
>
> uname = 'Ernst'
>
> class RoosterListView(LoginRequiredMixin, ListView):
> queryset = Roosters.objects.filter(startvc__range=(DatumStart,
> DatumEind),username=uname).order_by("startvc")[:35]
>
>
> This also works fine. So what I want todo is fill the variable 'uname' with
> the username from the logged in user. How do I do that. I can't get it done.
>
> For example I tried:
>
> from django.contrib.auth.models import User
>
> uname = User.username
>
> no errors but also no data.
>
> What am I doing wrong?
>
> Thanks in advance.
> Kind regards,
> Ernst
> -- 
> 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/f8e28e62-2e4b-4513-aa97-d1aa5f7776e2%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/2519e055-7898-d89a-827b-7ab4055a39f2%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can I close the feature that django orm will create table when a modal create?

2016-12-28 Thread Tim Graham
You'll want to set Meta.managed = False on the model.

https://docs.djangoproject.com/en/stable/ref/models/options/#managed

On Wednesday, December 28, 2016 at 7:17:31 AM UTC-5, tinybox wrote:
>
> Hi everyone,
> I am a beginner about django. 
> It seems django will create a table when the modal first create, but I 
> want to create table in database by myself and forbid django creating 
> table automatically. 
> What can I do in setting.py?
>
> 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/fa69ade1-676d-4f90-805a-9aebcaee269c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What is the best combination of components when installing Django on Windows 10?

2016-12-28 Thread Avraham Serour
There's nothing recommending not to use uwsgi on windows. Deploying on
windows may be not recommended, but if you must use it uwsgi may be
compiled in cygwin. Actually even nginx may be compiled in cygwin and works
fine

On Wed, Dec 28, 2016 at 5:03 AM, roboslone  wrote:

> Both nginx and Apache are cross-platform, so you could run them on Windows
> as your front-end servers. You can't use gunicorn and it's not recommended
> to use uWSGI on Windows (http://stackoverflow.com/
> questions/21071494/how-to-run-django-with-nginx-on-a-windows-machine),
> but you could still use mod_wsgi with apache. Nginx also has wsgi module.
>
> PostgreSQL, MySQL and sqlite can run on Windows, so you should have no
> problem with DB either.
>
> Personally I would recommend developing on Linux, since you'd probably
> deploy on linux servers eventually. You could rent a VPS or run Ubuntu on
> virtual machine like VirtualBox or VMWare (both supporting Windows as a
> host and many Linux distributions as guest OS), which is free, but could
> slow down your host machine.
>
> As to what's the best combination, I couldn't really tell. Personally I
> use PostgreSQL, gunicorn and nginx.
>
> On 26 Dec 2016, at 09:11, Varuna Seneviratna 
> wrote:
>
> Hello,
>  What is the best combination of components to be used when
> installing Django on Windows 10; By Components, I mean the database and the
> web Server.
>
>
> Thanks, Varuna
>
> --
> 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/CAKW-c0wiaY%3D9viR4r_A3yvNCPSGZbN6W-C5akZ-
> bRLXZgbiDOg%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/667B7DB2-FF63-4928-ACCA-DDDC06CD3403%40gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


using django app functionality offline in browser when internet is inactive and synchronize with the remote server when internet is available.

2016-12-28 Thread Shiv Dangi
I am making website for a restaurant that also serving food to home to 
their customers. I successfully completed online food ordering and serving 
part and also integrated counter management functionality in same website 
(all data related to counter management functionality are stored on remote 
database, this functionality  hit remote database many times for eg: when a 
new customer come to restaurant then generating a new order in database, a 
item is added/deleted to a customer order, storing waiter detail related to 
that order, and also context switching between orders because there are 
many customer at a time). now i want to use this functionality as a offline 
in browser when internet is inactive and putting all data related to orders 
in remote database when internet is available. can I do this thing using 
browser?

sorry for my bad English and Thanks in advance for helping me.   

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


Re: Django project beginner

2016-12-28 Thread jon
I would recommend the Django Girls tutorial. It is very well written and 
easy to follow. I covers most of the components that you will need to get 
started with Django and is a good starting point.

https://tutorial.djangogirls.org/en/

On Monday, December 26, 2016 at 6:39:25 AM UTC-5, imed chaabouni wrote:
>
> Hi everyone,
> I'm about to make my first project with Django as an end-of-year project, 
> so, could you recommand me some exemple as a beginner ?
> And if you've got some documentation that's would be great ( And yes I 
> already checked the doc of the official django website)
>
> Thanks, 
> Imed.
>

-- 
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/f8d7b6af-477a-4979-a8d0-d684b4162c04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What is the best combination of components when installing Django on Windows 10?

2016-12-28 Thread Kakar Nyori
Hi,

I use windows, and I too was confused about these things. The best 
recommendation I got was to use *Vagrant, *and to this day I use it. 

*"Vagrant is a tool for building complete development environments."*

Basically you select an environment like ubuntu OS (called vagrant box), 
and then you add it as your vagrant environment. With this as your local 
development you get many benefits:

1. Since you will eventually be using OS like ubuntu in production, you get 
the same environment for the development as well.
2. You can play around with the environment.
3. And since you have the production like environment, you can basically do 
all the stuff you would do in production. Like you want gunicorn, ok, 
install it in your vagrant environment and use it.
4. You can administer and practice in the machine like you would do for the 
production.
5. You can have the same exact configuration that is in your production 
machine.

Hope this will be helpful to you as it was for me. And again, this may not 
be the best practice for someone else.

Cheers!

Kakar.

-- 
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/dd29d891-2f17-411c-9a5c-a102e2ce0ae2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Url error

2016-12-28 Thread Matthew Pava
It looks like you need to remove “id/” from the URL in the address bar or add 
“id/” to the beginning of the URL in your urlpatterns.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Sharan Kumar
Sent: Wednesday, December 28, 2016 9:29 AM
To: Django users
Subject: Url error

I an new to django.I am getting the error as described in the images below.Help 
me with this.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/8c0d2076-e89a-405f-ab0d-672c8b667bbe%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/06720507a7544f499f11297867f035be%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Django doesn't email reporting an internal server error (HTTP status code 500)

2016-12-28 Thread Philip Lee
Please help! The question are also posted here
http://stackoverflow.com/questions/41363888/django-doesnt-email-reporting-an-internal-server-error-http-status-code-500

I could send mail using the following code

E:\Python\django-test\LYYDownloaderServer>python manage.py shell
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (In
tel)] on win32Type "help", "copyright", "credits" or "license" for more 
information.(InteractiveConsole)>>> from django.core.mail import 
send_mail>> send_mail(... 'Subject here',... 'Here is the 
message.',... 'redstone-c...@163.com',... ['2281570...@qq.com'],... 
fail_silently=False,... )1>>> 

According to the doc 

:

When DEBUG is False, Django will email the users listed in the ADMINS 
setting whenever your code raises an unhandled exception and results in an 
internal server error (HTTP status code 500). This gives the administrators 
immediate notification of any errors. The ADMINS will get a description of 
the error, a complete Python traceback, and details about the HTTP request 
that caused the error.

but in my case, Django doesn't email reporting an internal server error 
(HTTP status code 500) [image: enter image description here] 


what's the problem? please help fix the problem


settings.py

"""
Django settings for LYYDownloaderServer project.

Generated by 'django-admin startproject' using Django 1.9.1.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
ADMINS = [('Philip', 'r234327...@163.com'), ('Philip2', '768799...@qq.com')]
EMAIL_HOST = 'smtp.163.com'  # 'localhost'#'smtp.139.com'# EMAIL_PORT = 25# 
EMAIL_USE_TLS = True

EMAIL_HOST_USER = 'r234327...@163.com'  # '13529123...@139.com'
EMAIL_HOST_PASSWORD = '**'# DEFAULT_FROM_EMAIL = 'r234327...@163.com'# 
Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production# See 
https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 's4(z8qzt$=x(2t(ok5bb58_!u==+x97t0vpa=*8bb_68baekkh'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['127.0.0.1']#, '.0letter.com'

# Application definition

INSTALLED_APPS = [
'VideoParser.apps.VideoparserConfig',
'FileHost.apps.FilehostConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',]

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

ROOT_URLCONF = 'LYYDownloaderServer.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},]

WSGI_APPLICATION = 'LYYDownloaderServer.wsgi.application'

# Database# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}}

# Password validation# 
https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.NumericPasswordValidator',
},]

# Internationalization# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript,

RE: What is the best combination of components when installing Django on Windows 10?

2016-12-28 Thread Matthew Pava
For what it’s worth, I use Windows 10 as my development environment.  We use 
Windows Server 2012 in production with PostgreSQL and Apache 2.4 with modwsgi.  
We use Python 3.5 and Django 1.10.  All of our tools are 64-bit.  What’s really 
nice is that we have a method to print webpages directly from the server so the 
user doesn’t have to be pestered with all of the print dialog settings in his 
or her browser.  We use a combination of PhantomJS to render the page as PDF 
and gsprint for the actual printing.  In our legacy version of the project, we 
used Microsoft Access which had the nice feature of clicking on a print button 
to have the report sent directly to the printer, so we had to keep that feature 
going.  (Now we need to implement a feature for sending email through the 
user’s Exchange mailbox.  Previously, we could use ActiveX to open the user’s 
Outlook window.)

-- 
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/31eafe68ae954815969da0bf6e98c867%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Subclassing Models in non model class

2016-12-28 Thread M Hashmi
Thanks for the reply. I was trying to understand sql level inheritance
difference between Proxy based models and abstract models.

I got it figured out.
Thanks

Regards,
Mudassar

On Wed, Dec 28, 2016 at 4:09 AM, Melvyn Sopacua 
wrote:

> On Tuesday 27 December 2016 05:51:55 M Hashmi wrote:
>
>
>
> > I created a model Address like a normal practice below. Now I need to
>
> > create a subclass without using models.Model. But its not letting me
>
> > do because obviously it won't create tables unless I call
>
> > models.Model in class parameters.
>
> >
>
> > Idea is to create a model and use that model with non db reference in
>
> > admin.py. Following is the code:
>
>
>
> It's quite unclear what you want and why you want it especially. What does
> this other Address model represent?
>
> --
>
> 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/5208735.ZJ1U0fmsWf%40devstation
> 
> .
> 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/CANoUts4rinzvF%2BdHfuN8WKof6CjsXWE4O5w-J-MZoB%3DuGS3N6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Define Django Base Model Class

2016-12-28 Thread Guilherme Leal
In one of my django projects, I have a base model (that inherits 
from django.db.models.Model), and is the base model class that all my 
models uses.
I would like to "override" the base model class from django, so everytime a 
developer would import the base model class with "from 
django.db.models import Model", it would insted import my project's custom 
base model.

The result would be something like this:

from django.db import models

class MyModel(models.Model):
pass


>>> type(MyModel)



Any help would be apreciated!

-- 
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/649b3b97-17d3-4257-b473-f050440b4d14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Define Django Base Model Class

2016-12-28 Thread Avraham Serour
You could monkeypatch django to accomplish this, but I would advise against
it.

Instead of having implicit or hidden behaviour you should instruct your
developers to use from myproject import models instead of from django.db
import models


On Wed, Dec 28, 2016 at 7:13 PM, Guilherme Leal  wrote:

> In one of my django projects, I have a base model (that inherits
> from django.db.models.Model), and is the base model class that all my
> models uses.
> I would like to "override" the base model class from django, so everytime
> a developer would import the base model class with "from
> django.db.models import Model", it would insted import my project's custom
> base model.
>
> The result would be something like this:
>
> from django.db import models
>
> class MyModel(models.Model):
> pass
>
>
> >>> type(MyModel)
> 
>
>
> Any help would be apreciated!
>
> --
> 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/649b3b97-17d3-4257-b473-f050440b4d14%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/CAFWa6tJYC3ujmh096Tm9EmfnEixg2Buwa5oRehzMmgLAoUes%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Define Django Base Model Class

2016-12-28 Thread Guilherme Leal
Got it.

The custom model doesn't have any significantly different behaviour, just
some helper properties that return, for instance, a basic GrapQL Node from
that very model (the project uses graphene).

2016-12-28 15:46 GMT-02:00 Avraham Serour :

> You could monkeypatch django to accomplish this, but I would advise
> against it.
>
> Instead of having implicit or hidden behaviour you should instruct your
> developers to use from myproject import models instead of from django.db
> import models
>
>
> On Wed, Dec 28, 2016 at 7:13 PM, Guilherme Leal 
> wrote:
>
>> In one of my django projects, I have a base model (that inherits
>> from django.db.models.Model), and is the base model class that all my
>> models uses.
>> I would like to "override" the base model class from django, so everytime
>> a developer would import the base model class with "from
>> django.db.models import Model", it would insted import my project's custom
>> base model.
>>
>> The result would be something like this:
>>
>> from django.db import models
>>
>> class MyModel(models.Model):
>> pass
>>
>>
>> >>> type(MyModel)
>> 
>>
>>
>> Any help would be apreciated!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/649b3b97-17d3-4257-b473-f050440b4d14%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/CAFWa6tJYC3ujmh096Tm9EmfnEixg2Buwa5oRehzMmgLAoUes%3Dw%
> 40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


File/Folder Sync API?

2016-12-28 Thread Alexander Joseph
I'm building a collection of apps that write custom .docx and .xlsx files, 
and store them to a users account. These files need to be in a specific 
hierarchy and each user will have their own files/folders they can view and 
edit. It would really be great if I could allow each user to sync their 
files/folders to their local hard drives so they can view, print, etc. them 
outside of the web app. Does anyone know of a good API for doing this? I 
know SugarSync has an API but they charge their users something like $7/mo 
for their cheapest subscription. I'd like to make my apps free if at all 
possible. 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/57b50b62-6bce-4197-8414-2afd5be7943b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django-Channels strange slowdowns - how to profile?

2016-12-28 Thread jakub . skalecki


My question from StackOverflow:


My technology stack is Redis as a channels backend, Postgresql as a 
database, Daphne as an ASGI server, Nginx in front of a whole application. 
Everything is deployed using Docker Swarm, with only Redis and Database 
outside. I have about 20 virtual hosts, with 20 interface servers, 40 http 
workers and 20 websocket workers. Load balancing is done using Ingress 
overlay Docker network. Ouch, and I'm also using django-cacheops for low 
timeout caching (up to 15 min)


The problem is, sometimes very weird things happen regarding performance. 
Most of requests are handled in under 400ms, but sometimes request can take 
up to 2-3s, even during very small load. Profiling workers with Django 
Debug Toolbar or middleware-based profilers shows nothing (timing 50-100ms 
or so)


My question: is there any good method of profiling a whole request path 
with django-channels? I would like how much time each phase takes, i.e when 
request was processed by Daphne, when worker started processing, when it 
finished, when interface server sent response to the client. Currently, I 
have no idea how to solve this.


EDIT:

Some more information:

Website isn't that big, it tops at 1k users online, with some real-time 
features like notifications, chat, and real-time updates of few views. It 
looks like sometimes website is "blocked", like communication between redis 
/ interface servers / workers were incredibly slooow. 


Maybe you have some experience about server / worker ratios, fine tuning 
channel and redis settings? 



-- 
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/18cd97f8-5505-470b-8c22-3d97b1586d83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What determines initial number of forms in Django modelformset_factory?

2016-12-28 Thread Farhan Khan
I believe its the "extra" parameter.
By default, the size is the number of objects you pass it. You can set that 
value to 0 by doing YourObject.objects.none()

On Wednesday, December 28, 2016 at 7:17:31 AM UTC-5, Duane Gregory wrote:
>
> My model formset is producing an initial 7 forms, as seen here:
>
>  value="7" /> type="hidden" value="7" />
>
> I would like to alter that number, but cannot see how.
> view and form for ref:
>
> def micro_log_create(request):
> MicroLogFormSet = modelformset_factory(Micro_Log, form=MicroLogForm, 
> max_num=4, extra=0)
> if request.method == 'POST':
> formset = MicroLogFormSet(request.POST, request.FILES)
> if formset.is_valid():
> formset.save()
> return reverse('micro-log')
> else:
> formset = MicroLogFormSet()
> return render(request, 'app/micro_log/micro_log_create.html', 
> {'formset': formset})
>
> class MicroLogForm(forms.ModelForm):
> class Meta:
> model = Micro_Log   
> exclude = ['user', 'date_time']
> MicroLogFormSet = modelformset_factory(Micro_Log, form=MicroLogForm, 
> max_num=4, extra=0)
> formset = MicroLogFormSet()
>
> Thank you
>

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


Custom Widget for CharField Multiple

2016-12-28 Thread Farhan Khan
Hi,
I am trying to create a `CharFieldMultiple`, equivalent to the 
MultipleHiddenInput or SelectMultiple.

The goal is to have multiple CharField returned as a list, but have not 
been able to recreate it. My code thus far is:

class CharFieldMultiple(forms.widgets.Input):
def render(self, name, value, attrs=None):
if value is None:
value = []
final_attrs = self.build_attrs(attrs, type=self.input_type, name=
name)
inputs = []
for i, v in enumerate(value):
input_attrs = dict(value=force_text(v), **final_attrs)
inputs.append(format_html('', flatatt(input_attrs)))
return mark_safe('\n'.join(inputs))

I am trying to figure out how 'value' is set. I noticed that when I 
manually put value = ['a','b','c'], I will get 3 CharFields, great! But I 
cannot figure out how to pass that value parameter.

The type-field is still set to None, but I can figure that out later.
Thanks in advance!

- Farhan

-- 
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/2ecc728a-8d13-492d-91cf-e2fe155fc04b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Define Django Base Model Class

2016-12-28 Thread Vijay Khemlani
That doesn't change the advise

I would find it weird to import a class only to have something else loaded

https://www.python.org/dev/peps/pep-0020/

"Explicit is better than implicit."


On Wed, Dec 28, 2016 at 3:02 PM, Guilherme Leal  wrote:

> Got it.
>
> The custom model doesn't have any significantly different behaviour, just
> some helper properties that return, for instance, a basic GrapQL Node from
> that very model (the project uses graphene).
>
> 2016-12-28 15:46 GMT-02:00 Avraham Serour :
>
>> You could monkeypatch django to accomplish this, but I would advise
>> against it.
>>
>> Instead of having implicit or hidden behaviour you should instruct your
>> developers to use from myproject import models instead of from django.db
>> import models
>>
>>
>> On Wed, Dec 28, 2016 at 7:13 PM, Guilherme Leal 
>> wrote:
>>
>>> In one of my django projects, I have a base model (that inherits
>>> from django.db.models.Model), and is the base model class that all my
>>> models uses.
>>> I would like to "override" the base model class from django, so
>>> everytime a developer would import the base model class with "from
>>> django.db.models import Model", it would insted import my project's custom
>>> base model.
>>>
>>> The result would be something like this:
>>>
>>> from django.db import models
>>>
>>> class MyModel(models.Model):
>>> pass
>>>
>>>
>>> >>> type(MyModel)
>>> 
>>>
>>>
>>> Any help would be apreciated!
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/649b3b97-17d3-4257-b473-f050440b4d14%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/ms
>> gid/django-users/CAFWa6tJYC3ujmh096Tm9EmfnEixg2Buwa5oRehzMmg
>> LAoUes%3Dw%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAOs3Lp57Kwtoj8xJ6t1mwfaUv41RW%2BrBTozxbiyuAV3h9et5-g%
> 40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: What determines initial number of forms in Django modelformset_factory?

2016-12-28 Thread Duane Gregory
Perfect. Thank you!

On Wednesday, December 28, 2016 at 12:43:39 PM UTC-7, Farhan Khan wrote:
>
> I believe its the "extra" parameter.
> By default, the size is the number of objects you pass it. You can set 
> that value to 0 by doing YourObject.objects.none()
>
> On Wednesday, December 28, 2016 at 7:17:31 AM UTC-5, Duane Gregory wrote:
>>
>> My model formset is producing an initial 7 forms, as seen here:
>>
>> > value="7" />> type="hidden" value="7" />
>>
>> I would like to alter that number, but cannot see how.
>> view and form for ref:
>>
>> def micro_log_create(request):
>> MicroLogFormSet = modelformset_factory(Micro_Log, form=MicroLogForm, 
>> max_num=4, extra=0)
>> if request.method == 'POST':
>> formset = MicroLogFormSet(request.POST, request.FILES)
>> if formset.is_valid():
>> formset.save()
>> return reverse('micro-log')
>> else:
>> formset = MicroLogFormSet()
>> return render(request, 'app/micro_log/micro_log_create.html', 
>> {'formset': formset})
>>
>> class MicroLogForm(forms.ModelForm):
>> class Meta:
>> model = Micro_Log   
>> exclude = ['user', 'date_time']
>> MicroLogFormSet = modelformset_factory(Micro_Log, form=MicroLogForm, 
>> max_num=4, extra=0)
>> formset = MicroLogFormSet()
>>
>> Thank you
>>
>

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


How to pass data between Django module/app functions without using database in asynchronous web service

2016-12-28 Thread Ken McDonald
I've got a web service under development that uses Django and Django 
Channels to send data across websockets to a remote application. The 
arrangement is asynchronous and I pass information between the 2 by sending 
JSON formatted commands across websockets and then receive replies back on 
the same websocket.

The problem I'm having is figuring out how to get the replies back to a 
Javascript call from a Django template that invokes a Python function to 
initiate the JSON websocket question. Since the command question & data 
reply happen in different Django areas and the originating 
Javascript/Python functions call does not have a blocking statement, the 
Q&A are basically disconnected and I can't figure out how to get the 
results back to the browser.

Right now, my idea is to use Django global variables or store the results 
in the Django models. I can get either to work, but I beleive the Django 
global variables would not scale beyond multiple workers from runserver or 
if the system was eventually spread across multiple servers. 

But since the reply data is for different purposes (for example, list of 
users waiting in a remote lobby, current debugging levels in remote system, 
etc), the database option seems unworkable because the reply data is 
varying structure. That, plus the replies are temporal and don't need to be 
permanently stored in the database.

Here's some code showing the flow. I'm open to different implementation 
recommendations or a direct answer to the question of how to share 
information between the 2 Django functions.

In the template, for testing, I just have a button defined like this:

Request Lobby


With a Javascript function. This function is incomplete as I've yet to do 
anything about the response (because I can't figure out how to connect it):

$("#request_lobby").click(function(){
$.ajax({
type: "POST",
url: "{% url 'test_panel_function' %}",
data: { csrfmiddlewaretoken: '{{ csrf_token }}', button:
"request_lobby" },
success: function(response){
}
});
});


This is the Django/Python function in views.py . The return channel for the 
remote application is pre-stored in the database as srv.server_channel when 
the websocket is initially connected (not shown):

@login_required
def test_panel_function(request):

button = request.POST.get('button', '')

if button == "request_lobby" :
srv = Server.objects.get(server_key="1234567890")
json_res = []
json_res.append({"COMMAND": "REQUESTLOBBY"})
message = ({
"text": json.dumps(json_res)
})
Channel(srv.server_channel).send(message)
return HttpResponse(button)



Later, the remote application sends the reply back on the websocket and 
it's received by a Django Channels demultiplexer in routing.py :

class RemoteDemultiplexer(WebsocketDemultiplexer):
mapping = {
"gLOBBY"   : "gLOBBY.receive",
}
http_user = True
slight_ordering = True
  

channel_routing = [
route_class(RemoteDemultiplexer, path=r
"^/server/(?P[a-zA-Z0-9]+)$"),
route("gLOBBY.receive"   , command_LOBBY),
]



And the consumer.py :

@channel_session
def command_LOBBY(message):
skey = message.channel_session["server_key"]
for x in range(int(message.content['LOBBY'])):
logger.info("USERNAME:  " + message.content[str(x)]["USERNAME"])
logger.info("LOBBY_ID:  " + message.content[str(x)]["LOBBY_ID"])
logger.info("OWNER_ID:  " + message.content[str(x)]["IPADDRESS"
])
logger.info("DATETIME:  " + message.content[str(x)]["DATETIME"])


So I need to figure out how to get the reply data in command_LOBBY to the 
Javascript/Python function call in test_panel_function

Current ideas, both of which seem bad and why I think I need to ask this 
question for SO:

*1) Use Django global variables:*

Define in globals.py:

global_async_result = {}



And include in all relevant Django modules:

from test.globals import global_async_result


In order to make this work, when I originate the initial command in 
test_panel_function to send to the remote application (the REQUESTLOBBY), 
I'll include a randomized key in the JSON message which would be 
round-tripped back to command_LOBBY and then global_async_result dictionary 
would be indexed with the randomized key.

In test_panel_function , I would wait in a loop checking a flag for the 
results to be ready in global_async_result and then retrieve them from the 
randomized key and delete the entry in global_async_result.

Then the reply can be given back to the Javascript in the Django template.

That all makes sense to me, but uses global variables (bad), and seems that 
it wouldn't scale 

Re: using django app functionality offline in browser when internet is inactive and synchronize with the remote server when internet is available.

2016-12-28 Thread roboslone
Hi! Seems like this is a task for your frontend, not Django. You'd probably 
want to store orders data in client's browser and then call some handler on 
your backend (Django), that would correctly process this data. You should be 
careful, though, because clients could send malformed data to that handler and 
possibly corrupt your database or order something without paying.

> On 28 Dec 2016, at 17:32, Shiv Dangi  wrote:
> 
> I am making website for a restaurant that also serving food to home to their 
> customers. I successfully completed online food ordering and serving part and 
> also integrated counter management functionality in same website (all data 
> related to counter management functionality are stored on remote database, 
> this functionality  hit remote database many times for eg: when a new 
> customer come to restaurant then generating a new order in database, a item 
> is added/deleted to a customer order, storing waiter detail related to that 
> order, and also context switching between orders because there are many 
> customer at a time). now i want to use this functionality as a offline in 
> browser when internet is inactive and putting all data related to orders in 
> remote database when internet is available. can I do this thing using browser?
> 
> sorry for my bad English and Thanks in advance for helping me.   
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to django-users@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/668fa0cf-6c83-463c-92c7-8587fb29ceef%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/C5A90D19-E594-4DE1-83CF-C5030B27053A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Widget for CharField Multiple

2016-12-28 Thread roboslone
Hi! If I understand this correctly, subclassing `forms.widgets.Input` was a 
wrong idea.
As you can see in Input's source 
(https://docs.djangoproject.com/en/1.10/_modules/django/forms/widgets/#Input 
), 
it always renders single  tag, so you'd always get single value 
attribute from it, which is a string, not a list.

> On 28 Dec 2016, at 22:52, Farhan Khan  wrote:
> 
> Hi,
> I am trying to create a `CharFieldMultiple`, equivalent to the 
> MultipleHiddenInput or SelectMultiple.
> 
> The goal is to have multiple CharField returned as a list, but have not been 
> able to recreate it. My code thus far is:
> 
> class CharFieldMultiple(forms.widgets.Input):
> def render(self, name, value, attrs=None):
> if value is None:
> value = []
> final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
> inputs = []
> for i, v in enumerate(value):
> input_attrs = dict(value=force_text(v), **final_attrs)
> inputs.append(format_html('', flatatt(input_attrs)))
> return mark_safe('\n'.join(inputs))
> 
> I am trying to figure out how 'value' is set. I noticed that when I manually 
> put value = ['a','b','c'], I will get 3 CharFields, great! But I cannot 
> figure out how to pass that value parameter.
> 
> The type-field is still set to None, but I can figure that out later.
> Thanks in advance!
> 
> - Farhan
> 
> -- 
> 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/2ecc728a-8d13-492d-91cf-e2fe155fc04b%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/4EF670C7-C2D1-49EB-B35C-058070A0DD9A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.