Re: When do I have to call save() on a Model Instance?

2015-01-30 Thread Erik Cederstrand

> Den 29/01/2015 kl. 19.40 skrev Tobias Dacoir :
> 
> Thanks for answering all my questions.
> 
> So it's perfectly save to call the save method at a later time? As long as I 
> keep the object and a pointer to it in memory I can freely modify it in 
> several Functions before finally calling save at some point in time?

This depends on your requirements. If there's a chance that another thread has 
modified the same object in the database from the time you fetch the data and 
until you call save(), then it's not necessarily safe. This would depend on 
your use of transactions, whether the data has been submitted from a form etc.

You should audit your code for these things if race conditions are a concern to 
you.

Erik

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D46AC3C3-B2A3-4D09-8C9A-370AC0367DFB%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Namespace url lookup inside template of an app

2015-01-30 Thread Thorsten Sanders

Answering my own question, for the case someone else need it:

I am used to use render_to_response it not working with it, with using 
render it works with applying current_app, like this:


return render(request, 'myaddons/index.html', 
{'addons':addons,'game':game,},current_app=request.resolver_match.namespace)


Am 29.01.2015 um 21:24 schrieb Thorsten Sanders:

Hello,

writing currently an app which should show different things based on 
namespace which is working already, but I do have problems with 
generating the right url inside the templates of that app.

I tried to use:
{% url 'myaddons:index' %}
but that always shows the same namespace url the last one attached.

Currently have defined inside that app:
urlpatterns = patterns('',
url(r'^$', 'myaddons.views.index', name='index'),
)

Then have 2 other apps in one I define:
urlpatterns = patterns('',
   url(r'^addons/', include('myaddons.urls', 
namespace='wow-myaddons', app_name='myaddons')),

)

in the other one:
urlpatterns = patterns('',
   url(r'^addons/', include('myaddons.urls', namespace='ws-myaddons', 
app_name='myaddons')),

)

The base one is:

url(r'^wow/', include('warcraft.urls')),
url(r'^ws/', include('wildstar.urls')),

With what I tried it always resolve to:
/ws/addons/

I want it to resolve to:
/wow/addons/ if called with /wow/
and
/ws/addons/ if called with /ws/

Greetings,
Thorsten



--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54CB8061.4060904%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: Create Django token-based Authentication

2015-01-30 Thread Collin Anderson
Hi,

What happens when you try? :)

Your setup is pretty complicated, but I don't know if REST framework will 
help much.

Collin

On Tuesday, January 27, 2015 at 12:00:59 AM UTC-5, Hossein Rashnoo wrote:
>
> I have my authentication service on django. I want to role as web-service 
> to gave other website a token and authenticate users with that token.
>
> This is my scenario:
>
>1. user visit external website and try to login
>2. when hit the login button that website redirect user to my site to 
>use username and password for login
>3. When successfully logged in users will redirect to external website 
>with a token
>4. And every time that website send me that token, I recognize that 
>user and pass some data to external website I'm try to use REST-Framework 
>authentication but it is too complicated Please help me.
>
>

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


Re: path to django from jython

2015-01-30 Thread Collin Anderson
Hi,

I think you to make sure django is on your PYTHONPATH / sys.path

Collin

On Tuesday, January 27, 2015 at 10:51:13 AM UTC-5, Josh Stratton wrote:
>
> Okay, stupid question, but how do I source django when jusing jython?  I 
> have django installed using pip and jython installed locally.  I've built 
> my project using python and after adding "doj" to the installed apps, I get 
> a path error building a war.  
>
> $ jython manage.py buildwar
> Traceback (most recent call last):
>   File "manage.py", line 8, in 
> from django.core.management import execute_from_command_line
> ImportError: No module named django
>
> https://pythonhosted.org/django-jython/war-deployment.html
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1d542d5c-07ed-46c0-ad6d-4fc3bab8e29e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django / tastypie - how to exclude a resource attribute from obj_create, but keep it for listing

2015-01-30 Thread Collin Anderson
Hi Eugene,

Would it work to something like this in your obj_create?
bundle.data.pop('blueprint', None)

Collin

On Tuesday, January 27, 2015 at 11:01:56 AM UTC-5, Eugene Goldberg wrote:
>
>   I have the following tastypie resource:
>
>  class WorkloadResource(ModelResource):
> # blueprints = ManyToManyField(Blueprint, 'blueprints')
> blueprint = fields.OneToManyField('catalog.api.BlueprintResource', 
> attribute='blueprint',
>  related_name='workloads', full=True, 
> null=True)
>
> def obj_create(self, bundle, request=None, **kwargs):
> # return super(WorkloadResource, self).obj_create(bundle, request, 
> **kwargs)
> return super(WorkloadResource, self).obj_create(bundle, 
> request=request, **kwargs)
>
> def obj_update(self, bundle, request=None, **kwargs):
>
> workload = Workload.objects.get(id=kwargs.get("pk"))
> workload.description = bundle.data.get("description")
> workload.name = bundle.data.get("name")
> workload.image = bundle.data.get("image")
> workload.flavor = bundle.data.get("flavor")
> workload.save()
>
> def obj_delete(self, bundle, **kwargs):
>
> return super(WorkloadResource, self).obj_delete(bundle)
>
> def determine_format(self, request):
> return 'application/json'
>
> class Meta:
> queryset = Workload.objects.all()
> resource_name = 'workload'
> authorization=Authorization()
> filtering = {
> "blueprint": ('exact', ),
> }
>
>
>  When I use curl to POST: 
>
>  curl -i -H "Content-Type: application/json" -X POST -d 
>  @wkl.json  http://localhost:8000/api/workload/
>
>  where wkl.json is:
>
>  { "name":"w 5", "description":"w 5 desc" }
>
>
>  I get this error:
>
>  AttributeError: 'Workload' object has no attribute 'blueprint'
>
>  I do need to have this attribute, so I can list all child workloads for a 
> given blueprint 
>  like this:  GET /api/workload/?blueprint=1
>
>  but I need to exclude this 'blueprint' attribute from participating in 
> the obj_create
>
>  What is the proper place and syntax to do this?
>
>
> -Eugene
>
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7940ec09-b130-43ab-ab43-c25a26466284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create Django token-based Authentication

2015-01-30 Thread Guilherme Leal
Django REST Framework  already
implements token authentication (check this

out).

The rest of the logic is preaty much implementation by the "client" site.

But if you do want to implement some authentication form, you could create
a view that exibits an i frame, that would be loaded inside a popup box by
the client site.

That preaty much covers your problem.

Em Fri Jan 30 2015 at 11:22:36, Collin Anderson 
escreveu:

> Hi,
>
> What happens when you try? :)
>
> Your setup is pretty complicated, but I don't know if REST framework will
> help much.
>
> Collin
>
>
> On Tuesday, January 27, 2015 at 12:00:59 AM UTC-5, Hossein Rashnoo wrote:
>>
>> I have my authentication service on django. I want to role as web-service
>> to gave other website a token and authenticate users with that token.
>>
>> This is my scenario:
>>
>>1. user visit external website and try to login
>>2. when hit the login button that website redirect user to my site to
>>use username and password for login
>>3. When successfully logged in users will redirect to external
>>website with a token
>>4. And every time that website send me that token, I recognize that
>>user and pass some data to external website I'm try to use REST-Framework
>>authentication but it is too complicated Please help me.
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/cc8def1e-9788-41ef-8896-4632b0d3b1ea%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOs3Lp55dZZiOH-u4SWW9sVE4-mBisauWEXpbUEszd_e2FLE4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best practice to render the view based on the user

2015-01-30 Thread Collin Anderson
Hi,

Not sure about whether it's a good idea or not. If statements might also be 
good enough.

Be careful with security, but in theory something like this should work:

method_name = 'person' + person.type
method = getattr(self, method_name)
output = method()

Collin

On Wednesday, January 28, 2015 at 12:04:06 AM UTC-5, Karim Gorjux wrote:
>
> Hi! I would like to render views based on the user. I have some differents 
> type of users on my app and I would like to create a class like this one 
> for the view:
>
> class MyView(MyCustomView)  # MyCustomView subclass View 
>
> def __init__(self, *args, **kwargs):
> # common code for all persons
>
> def personA(self):
> # code for personA
>
> def personB(self):
> # code for personA
>
> # 
>
> def personN(self):
> # code for personA
>
> def anyPerson(self)
> # For any user non listed above
> 
>
> Then if the MyView is run, the function based on the user is automatically 
> fired.
>
> My doubts (at the moment):
>
> 1) Do you think is the a good way to face the problem?
>
> 2) I have methods in the models to know what person is logged. How I can 
> automatically load the right function in the class based on the user?
>
> Thank you
>
> -- 
> Karim N. Gorjux
>  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7c787485-1566-4aaf-af91-be853337e107%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Reduce start up time for manage.py

2015-01-30 Thread Collin Anderson
Hi,

Many people would recommend against this, but if you can put the imports 
for your heavy 3rd party libraries inside functions and methods, that allow 
them to be loaded only if needed.

I would also recommend in general to simply have fewer libraries and apps 
(easier said than done :)

Also, is it slow only for the first load, or are repeated loads slow too?

I hope you aren't doing database queries or other expensive calls on 
startup.

Try putting this at the top of your manage.py to see more of what's going on

import logging; logging.basicConfig(level=logging.DEBUG)

Collin

If you want some benchmarks, here are some of my websites
221243 function calls (214987 primitive calls) in 0.394 seconds
448659 function calls (437433 primitive calls) in 0.611 seconds 
698349 function calls (687730 primitive calls) in 0.749 seconds

On Wednesday, January 28, 2015 at 4:42:09 AM UTC-5, chj wrote:
>
> Hi,
>
> I'm having a quite large Django project with dozens of apps and many 
> reusable third-party libraries. All the custom management commands (being 
> used with manage.py ) take a long time to be executed, since the 
> start up sequence takes between 3 and 5 seconds. Using the cProfile module 
> I was able to see that quite a lot of function calls are executed and it 
> looks like that every app is loaded, including its libraries and such 
> before the actual management command is executed. Is there any common way 
> to speed that up (e.g. by not loading apps/libraries that are not required 
> for a specific management command)? Django 1.7+ is used on Python 3.4.
>
> Output from `python3 -m cProfile manage.py` (truncated): 1100697 function 
> calls (1064507 primitive calls) in 5.172 seconds
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ac3ca3d-78a5-49bf-be96-05bc0017bf40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to detect (daily) User Login when using cookies?

2015-01-30 Thread Collin Anderson
Hi,

If you use a custom authentication backend, you could update it every time 
get_user(request) is called.

Collin

On Wednesday, January 28, 2015 at 4:58:30 AM UTC-5, Tobias Dacoir wrote:
>
> Yes that would be enough. I know in the User Model there is last_login but 
> that is only updated when the User actually logs in. And the signal from 
> django-allauth is also only send when the user uses the login form. The 
> only other alternative I found was to check in every view I have for 
> request.user and store / update datetime.now. But this is quite ugly.
>
>
> On Tuesday, January 27, 2015 at 9:00:15 PM UTC+1, Collin Anderson wrote:
>>
>> Hi,
>>
>> Would it make sense to simply keep a record of when the last time you've 
>> seen the user is?
>>
>> Collin
>>
>> On Friday, January 23, 2015 at 4:43:41 AM UTC-5, Tobias Dacoir wrote:
>>>
>>> I'm using django-allauth and I receive a signal when a user logs in. Now 
>>> I want to store each day the user logs in. However, when the user does not 
>>> logout he can still log in the next day thanks to the cookies. I know that 
>>> I can set SESSION_EXPIRE_AT_BROWSER_CLOSE to True in settings.py. But this 
>>> may annoy some Users. 
>>>
>>> So is there a way to use cookies but still tell if a User has accessed 
>>> the site for the first time today?
>>>
>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d2d6d493-2c95-43c1-a1ae-c08b9e0fbea4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Putting picture thumbnails within admin page

2015-01-30 Thread Nelson Varela
Make sure you are serving the media fles usins django's static server

from django.conf import settings 
urlpatterns += patterns('', 
url(r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': 
settings.MEDIA_ROOT, 'show_indexes': False}), )





On Tuesday, January 27, 2015 at 1:31:54 AM UTC+1, bradford li wrote:
>
>
> I am trying to put thumbnail pictures of my photos within my admin page. I 
> am currently running into the issue where the thumbnail isn't displayed, 
> when I click on thumbnail I am redirected to the homepage of my project 
> with this as the URL: 
>
> http://127.0.0.1:8000/media/tumblr_ngotb4IY8v1sfie3io1_1280.jpg
>
> Here is a gist of my code: 
>
> https://gist.github.com/liondancer/678752e8bf31cc7d2c63
>
> Stackoverflow question:
>
>
> http://stackoverflow.com/questions/28159740/configuring-admin-to-display-thumnails
>
> If anything else is needed please let me know! 
>
>
>
> 
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/28015f00-5b4c-45ea-97d5-d19955763c49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Middleware + Transactions

2015-01-30 Thread Thomas Güttler

Dear Django developers,

we currently have the following issue when upgrading from Django 1.5 to Django 1.6: 
https://github.com/etianen/django-reversion/issues/268


As it seems, since Django 1.6, middlewares are not supposed to be executed within the same transaction as the view 
function is.


We would like to understand why that is the default behavior now and we are supposed to re-organize our code base to 
work with that changes.


What is the rationale behind middlewares not being executed within the same 
transaction as the view function?

Furthermore, decorating all view functions as suggested here 
http://django-reversion.readthedocs.org/en/latest/api.html#revisionmiddleware is quite not feasible for large projects. 
Especially given that reversion is not the only middleware that needs to be executed within the same transaction as the 
view function. It would basically mean that each view function needs to be decorated potentially n times.



We understand that transactions might effect performance, thus lesser transactions being in a transaction means faster 
execution. However, shouldn't there be the possibility to include distinct middlewares into the view transaction?


Regards,
  Thomas Güttler

--
Thomas Güttler
http://thomas-guettler.de/

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54CB8E78.7060604%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.


Re: Reduce start up time for manage.py

2015-01-30 Thread Avraham Serour
I believe putting imports inside functions would slow down execution, it
will make the import everytime the function is executed

one could make something like a lazy import, but you would be trading slow
startup for slow requests

On Fri, Jan 30, 2015 at 3:49 PM, Collin Anderson 
wrote:

> Hi,
>
> Many people would recommend against this, but if you can put the imports
> for your heavy 3rd party libraries inside functions and methods, that allow
> them to be loaded only if needed.
>
> I would also recommend in general to simply have fewer libraries and apps
> (easier said than done :)
>
> Also, is it slow only for the first load, or are repeated loads slow too?
>
> I hope you aren't doing database queries or other expensive calls on
> startup.
>
> Try putting this at the top of your manage.py to see more of what's going
> on
>
> import logging; logging.basicConfig(level=logging.DEBUG)
>
> Collin
>
> If you want some benchmarks, here are some of my websites
> 221243 function calls (214987 primitive calls) in 0.394 seconds
> 448659 function calls (437433 primitive calls) in 0.611 seconds
> 698349 function calls (687730 primitive calls) in 0.749 seconds
>
> On Wednesday, January 28, 2015 at 4:42:09 AM UTC-5, chj wrote:
>>
>> Hi,
>>
>> I'm having a quite large Django project with dozens of apps and many
>> reusable third-party libraries. All the custom management commands (being
>> used with manage.py ) take a long time to be executed, since the
>> start up sequence takes between 3 and 5 seconds. Using the cProfile module
>> I was able to see that quite a lot of function calls are executed and it
>> looks like that every app is loaded, including its libraries and such
>> before the actual management command is executed. Is there any common way
>> to speed that up (e.g. by not loading apps/libraries that are not required
>> for a specific management command)? Django 1.7+ is used on Python 3.4.
>>
>> Output from `python3 -m cProfile manage.py` (truncated): 1100697
>> function calls (1064507 primitive calls) in 5.172 seconds
>>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0ac3ca3d-78a5-49bf-be96-05bc0017bf40%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6t%2BWW%2B4C-wuFxQY-nQfTviD7pRZRoMk5RxFC2j_AF3KWZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create Django token-based Authentication

2015-01-30 Thread François Schiettecatte
I wonder if OAuth would help you, see http://oauth.net

François

> On Jan 30, 2015, at 8:22 AM, Collin Anderson  wrote:
> 
> Hi,
> 
> What happens when you try? :)
> 
> Your setup is pretty complicated, but I don't know if REST framework will 
> help much.
> 
> Collin
> 
> On Tuesday, January 27, 2015 at 12:00:59 AM UTC-5, Hossein Rashnoo wrote:
> I have my authentication service on django. I want to role as web-service to 
> gave other website a token and authenticate users with that token.
> 
> This is my scenario:
> 
>   • user visit external website and try to login
>   • when hit the login button that website redirect user to my site to 
> use username and password for login
>   • When successfully logged in users will redirect to external website 
> with a token
>   • And every time that website send me that token, I recognize that user 
> and pass some data to external website I'm try to use REST-Framework 
> authentication but it is too complicated Please help me.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/cc8def1e-9788-41ef-8896-4632b0d3b1ea%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9104F84F-0C1B-4D22-B972-27BC6EC46B93%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Custom model field and custom widget

2015-01-30 Thread Thomas Weholt
Hi,

I need to create a custom django model field, a varchar(10) field which has 
a calculated value set on save on the model using it and then never 
changed. This should happen automatically. This field should appear as 
hidden or read-only in forms and it would be nice to handle the render 
output if the field is accessed in templates. The calculated value 
generated on save must access the database and look into a seperate table 
to calculate its value, ie. I need to control the generation of the value 
it gets.

Any ideas or hints?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/282086f4-31fc-47c7-9d6b-62fd8e05e556%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Reduce start up time for manage.py

2015-01-30 Thread Daniel Roseman
On Friday, 30 January 2015 14:01:17 UTC, Avraham Serour wrote:
>
> I believe putting imports inside functions would slow down execution, it 
> will make the import everytime the function is executed
>
> one could make something like a lazy import, but you would be trading slow 
> startup for slow requests
>

That is not true. Python imports are always only executed once: if the 
module already exists in `sys.modules`, it is not loaded again. 
--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/22833f7f-35b9-4c2b-a028-e60f79e065ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to detect (daily) User Login when using cookies?

2015-01-30 Thread Tom Evans
On Fri, Jan 30, 2015 at 1:50 PM, Collin Anderson  wrote:
> Hi,
>
> If you use a custom authentication backend, you could update it every time
> get_user(request) is called.
>

HTTP is stateless, authentication happens every request, so that gets
called on every request, causing session modification on each request.

How about:

from django.utils import timezone

class DailyLoginMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
today = timezone.now().strftime('%Y%m%d')
if request.session.get('last_seen') != today:
request.session['last_seen'] = today
setattr(request, 'new_today', True)

Store todays date in the session, check to see if it is changed, only
modify the session if the date has changed, set an attribute on the
request so that later views can include that information.

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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1JE6ZrMzLAdxCuOowe3hL3%3DmOZOPRx13YAzFqKSfufG4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


using Django on an existing mysql schema

2015-01-30 Thread William Muriithi
‎Hello,

I am new to Django and planning to use it for a project I have in mind. I am 
strong in mysql, but not too good in developing. In fact, the secondary purpose 
of this project is to improve my python development skills.

With such a background, I went about doing my data modeling and then set up 
views on top to de normalize the underlying schema and pushing most of the 
business logic in mysql. I want to use Django mainly to insert and display, 
which increases the chance of success with few bugs.

Problem is, with Django, it seems things are done the other way around. After 
playing with it, I noticed it changes the keys from unsigned to signed, 
something I feal is bad from database point of view. It converted enum to char, 
which to me is less appealing. In short, I don't like the change its 
introducing. ‎

My question is, can one use Django with an existing database without getting in 
trouble with the framework? I believe this has to be possible somehow as most 
companies work from data backwards. Would appreciate a good advice on how you 
guys and girls went‎ about using Django from existing schema. Or a Django book 
that take that perspective. The once I have read advice me to leave database 
work to orm.

Regards,

William
‎

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150130144722.6033553.12834.14799%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to detect (daily) User Login when using cookies?

2015-01-30 Thread Tobias Dacoir
Thanks. Though I do not use a Custom Authentication Backend, it should be 
possible to inherit from the Default one and just overwrite the get_user 
Method. 
I will test it out.

On Friday, January 30, 2015 at 3:56:10 PM UTC+1, Tom Evans wrote:
>
> On Fri, Jan 30, 2015 at 1:50 PM, Collin Anderson  > wrote: 
> > Hi, 
> > 
> > If you use a custom authentication backend, you could update it every 
> time 
> > get_user(request) is called. 
> > 
>
> HTTP is stateless, authentication happens every request, so that gets 
> called on every request, causing session modification on each request. 
>
> How about: 
>
> from django.utils import timezone 
>
> class DailyLoginMiddleware(object): 
> def process_request(self, request): 
> if request.user.is_authenticated(): 
> today = timezone.now().strftime('%Y%m%d') 
> if request.session.get('last_seen') != today: 
> request.session['last_seen'] = today 
> setattr(request, 'new_today', True) 
>
> Store todays date in the session, check to see if it is changed, only 
> modify the session if the date has changed, set an attribute on the 
> request so that later views can include that information. 
>
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a7e4a2e-2f05-45e4-9633-14d60dce78a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Do Signals block Django process?

2015-01-30 Thread Tobias Dacoir
I just added django-badges to my project. Basically it can award Badges if 
Users fullfill certain requirements. For this, everytime I call user.save() 
django-badges receives the post_save() signal and starts checking. 

Now my project is similar to an online quiz, where users submit forms to 
answer questions. Right now I only have tested it locally and I'm not sure 
how to simulate multiple users accessing the page at the same time. 

When later run on production in combination with a webserver, will Django 
spawn a new thread for each connection / user? Or will there be only one 
thread, so if two users are accessing the website, the 2nd has to wait 
until the request from the first user is processed?

Also what about my signal to process the badges. If I have a function that 
calls user.save(), which then signals to the badges module, will the 
execution of the original function stop until the signal has been processed 
or not?

def myView(request):
   do_something()
   request.user.save()
   # signal emitted
   # ... 
   render(view)

So in this case, will the view be rendered immediately or only after the 
receiver for the signal has finished doing it's work? In my case I don't 
really need it to be asynchronous as long as the badge checking is fast 
enough and doesn't block the website for other users.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f3b2f9dd-4681-48a1-8d49-79f73d45d0eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to get hold of a session after getting signaled?

2015-01-30 Thread Tobias Dacoir
I'm using django-badges in my project which can emit a signal when a user 
is awarded a badge. I was able to implemented a receiver function, however 
the output is the following:

signals.py (from badges):
import django.dispatch

badge_awarded = django.dispatch.Signal(providing_args=['user', 'badge'])



my receiver function test:

from badges.signals import badge_awarded
@receiver(badge_awarded)
def do_something_after_badge_awarded(sender, user, badge, **kwargs):
print "Badge Signal received"
print sender # 
print user # user object
print badge # badge object
print kwargs



and the output was:
Badge Signal received

player1
Test Badge 2
{'signal': }


I want to add a message to the request, to notify or show the user that he 
earned a badge. Is it possible someone get hold of the request? I can 
freely modify the original source code from django-badges. Currently it's 
invoked by post_save() on a model instance. So I doubt I can get the 
request from there. 

I found a solution to add another 3rd party app which is called 
django-notification, but I don't want to add too many apps to my project. 
Another solution might be to just set some variable in the database and in 
my view to query this variable - however that will also cost performance 
and two database hits.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e8f655c-8385-46aa-94ae-2c5baef2034a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Do Signals block Django process?

2015-01-30 Thread Vijay Khemlani
The number of threads is determined by the number of workers in your
process that is serving the application, not Django itself.

For example, if you are using uWSGI to serve the application, then you have
a parameter "workers" in its initialization file that sets the number of
process to spawn and handle incoming requests.

As far as I know, signals are processed "in sync", that is, the original
function is stopped until the signal has been processed. If you need async
functionality you would need to take a look at celery or something along
those lines.

On Fri, Jan 30, 2015 at 1:13 PM, Tobias Dacoir  wrote:

> I just added django-badges to my project. Basically it can award Badges if
> Users fullfill certain requirements. For this, everytime I call user.save()
> django-badges receives the post_save() signal and starts checking.
>
> Now my project is similar to an online quiz, where users submit forms to
> answer questions. Right now I only have tested it locally and I'm not sure
> how to simulate multiple users accessing the page at the same time.
>
> When later run on production in combination with a webserver, will Django
> spawn a new thread for each connection / user? Or will there be only one
> thread, so if two users are accessing the website, the 2nd has to wait
> until the request from the first user is processed?
>
> Also what about my signal to process the badges. If I have a function that
> calls user.save(), which then signals to the badges module, will the
> execution of the original function stop until the signal has been processed
> or not?
>
> def myView(request):
>do_something()
>request.user.save()
># signal emitted
># ...
>render(view)
>
> So in this case, will the view be rendered immediately or only after the
> receiver for the signal has finished doing it's work? In my case I don't
> really need it to be asynchronous as long as the badge checking is fast
> enough and doesn't block the website for other users.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f3b2f9dd-4681-48a1-8d49-79f73d45d0eb%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1CTR1-wMjqGwWv-cMp1wHhaPV0YzJm65Mw8-wLYyoUuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Do Signals block Django process?

2015-01-30 Thread Tobias Dacoir

Thanks for always answering my questions :)

I did read the documentation on uWSGI and I think I have an understanding 
now of workers and threads (from Webserver or uWSGI) and how it handles 
multiple users.

For the signals and badge calculation, I did see celery pop up a couple of 
times and I did briefly look at their documentation. In theory I don't need 
this though because when the user submits a form, I want to check for 
achievements before showing him the results page. If I use celery then it 
might happen that the new view is rendered while the achievements are still 
being processed. Maybe I will have to go this route at some point but then 
I face two new problems (one of which I already have):
a) I need to figure out how to get the request that won a badge in order to 
send him a message (for this I opened an extra thread)
b) I would need to modify his current view, something like using Websocket. 
I did a quick google search in the past and apparently using websocket and 
django is not so easy. So if I can avoid it, I'm happy.

If I know that the signals are processed in sync, and before the new view 
is rendered, then I can just have the code after the signal check if a 
badge has been awarded and then render the view. Phew, still quite 
complicated.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a1f83580-11fc-414d-b806-9a0e5ed106ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: using Django on an existing mysql schema

2015-01-30 Thread Tobias Dacoir
I'm certainly no Django expert, but I'm not sure if you can use the orm and 
an already existing database. However the documentation states that you can 
write all queries yourself, essentially not using the orm. However if you 
do that, I'm wondering why you want to use Django at all?
And pushing business logic into the database sounds like bad design to me 
(model and controller should be decoupled in MVC like patterns).

About the signed and unsigned changes - did you check the documentation: 
https://docs.djangoproject.com/en/1.7/ref/models/fields/
And enum is (afaik) not available in Python, maybe that's why it changed it 
to char.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b7bd5fcc-4093-401e-84fc-8c3175d9ee68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django web hosts in Canada

2015-01-30 Thread Carlos Carcamo
Why don't you try Digitalocean?
Take a look at those articles:
https://www.digitalocean.com/community/tutorials/how-to-use-the-django-one-click-install-image
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn

If you want $10 credit on digitalocean, use this link for register your
account
https://www.digitalocean.com/?refcode=b049a5d14734


2015-01-29 13:28 GMT-06:00 Avraham Serour :

> look for a vps and not a shared hosting, something like what you would get
> with AWS
>
> on the downside you will need to do everything yourself (installing and
> configuring all the libraries, updating the server etc)
>
> on the plus side it will be more flexible, it will support anything you
> would like
>
> On Thu, Jan 29, 2015 at 5:09 PM, jogaserbia  wrote:
>
>> Hi All,
>>
>> I would like to deploy my first Django website in the next month or so.
>> I am looking at deployment options, but need some clarification.
>>
>> 1) when id doesn't matter where the servers are
>>
>> I understand that  in terms of PASS: heroku, AWS, and Google elastic
>> beanstalk can all handle Django (python) and postres.
>>
>> If I want to host on a 'normal' hosting service, which would be
>> available? greengeeks just told me that they support Python but not Django,
>> which confused me because I thought Django was fully written in Python, so
>> I am clearly not understanding the complexities of deploying.  Also, they
>> only use MYSQL databases, I wrote my first app using Postgres/POSTGIS as
>> the database.
>>
>> 2) when I need servers in Canada
>>
>> Due to privacy concerns, I may need to use servers that are exclusively
>> in Canada.  I cannot seem to find any options on how to host Python/Django
>> and postres on Canadian servers.  Does anyone have any pointers on that?
>>
>>
>> Any advice would be appreciated, as this will be my first run at
>> deploying.
>>
>> I have been through the heroku example, and it seems nice and easy to
>> deploy and I can use Django and they use postgres.
>>
>> Ivan
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/d489e516-94d8-46e2-a212-438faa404452%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFWa6tLOviREvHPDT_G8K_q4E_g_NrpQuPuKKDHguE0ra%3D6isw%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"El desarrollo no es material es un estado de conciencia mental"

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADpTsTbSdK6QQK%2BD6Fr1%2Bh2Cyieait3e3poageoX6mh3VV-cXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Best Practices Django Questions

2015-01-30 Thread G Z
Hello, I'm in the design stages of a site that I'm building. It is going to 
be a basic social media site for a game I'm designing in unity. I'm not 
entirely sure how to do some of the things I want to in Django. Thus, my 
first question is generally best practices question as well as a how do I 
do this question.

Qustion #1: How do I set up my models field so that when a user uploads an 
image to a filefield it attaches the users name to the file that is being 
uploaded? Should I do this in the view or in the database?

Question #2: Examine my model design and tell me what I can do better, if 
I'm missing anything etc. I'm new to django so go easy. I didn't do the def 
and functions and class stuff just the over all structure. If it would be 
better if I posted that let me know and I will.

Question#3 How do I make the page when a user logs in resolve to his 
username, and how do I use the username as the url so when you click on a 
list of friends it uses that friends username as the url for their profile 
and resolves to thier page, a quick overview on the best way to do this 
would be just fine. Just point me and kinda explain the theory and I'm sure 
I can figure out the rest. 

Please just help me think of things I need to worry about design with 
django im just starting and I dont have a good base to go on.


User

id = models.*AutoField*(primary_key=True)

username = models.CharField(max_length=4000)

password = models.CharField(max_length=4000)

email = models.CharField(max_length=4000)

phone = models.CharField(max_length=4000)

profile_image = models.FileField()

about = models.CharField(max_length=4000)

hometown = models.CharField(max_length=4000)

job = models.CharField(max_length=4000)

score = models.CharField(max_length=4000)

hobbies = models.CharField(max_length=4000)

datetime = models.DateField()


Album

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

name = models.CharField(max_length=4000)

imageid = models.ForeignKey(Image)

datetime = models.DateField()


 Image

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

image = models.FileField()

imgdesc = models.CharField(max_length=4000)

datetime = models.DateField()

 Image_Comment

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

imageid = models.ForeignKey(Image)

comment = models.CharField(max_length=4000)

datetime = models.DateField()


 Image_Likes

id = models.*AutoField*(primary_key=True)

imageid = models.ForeignKey(Image)

userid = models.ForeignKey(User)

datetime = models.DateField()


 Post

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

message = models.CharField(max_length=4000)

image = models.FileField()

embed_link = models.CharField(max_length=4000)

liked_count = models.CharField(max_length=4000)

datetime = models.DateField()


 Post_Comment

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

postid = models.ForeignKey(Post)

comment = models.CharField(max_length=4000)

datetime = models.DateField()


 Post_User_Likes

id = models.*AutoField*(primary_key=True)

postid = models.ForeignKey(Post)

userid = models.ForeignKey(User)

datetime = models.DateField()


 User_Friends

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

friendid = models.ForeignKey(User)

blocked = models.CharField(max_length=4000)

datetime = models.DateField()


Reported

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

friendid = models.ForeignKey(User)

comment = models.CharField(max_length=4000)

datetime = models.DateField()

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/71830c67-c98c-4e38-95f8-235f7c1b9d81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Practices Django Questions

2015-01-30 Thread G Z
 

class *User*(models.Model):

id = models.*AutoField*(primary_key=True)

username = models.CharField(max_length=4000)

password = models.CharField(max_length=4000)

email = models.CharField(max_length=4000)

phone = models.CharField(max_length=4000)

profile_image = models.FileField()

about = models.CharField(max_length=4000)

hometown = models.CharField(max_length=4000)

job = models.CharField(max_length=4000)

score = models.CharField(max_length=4000)

hobbies = models.CharField(max_length=4000)

datetime = models.DateField()

class *Meta*:

managed=True


 class *Album*(models.Model):

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

name = models.CharField(max_length=4000)

imageid = models.ForeignKey(Image)

datetime = models.DateField()

class *Meta*:

managed=True


 class *Image*(models.Model):

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

image = models.FileField()

imgdesc = models.CharField(max_length=4000)

datetime = models.DateField()

class *Meta*:

managed=True


 class *ImageComment*(models.Model):

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

imageid = models.ForeignKey(Image)

comment = models.CharField(max_length=4000)

datetime = models.DateField()

class *Meta*:

managed=True


 class *ImageLike*(models.Model):

id = models.*AutoField*(primary_key=True)

imageid = models.ForeignKey(Image)

userid = models.ForeignKey(User)

datetime = models.DateField()

class *Meta*:

managed=True


 class *Post*(models.Model):

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

message = models.CharField(max_length=4000)

image = models.FileField()

embed_link = models.CharField(max_length=4000)

liked_count = models.CharField(max_length=4000)

datetime = models.DateField()

class *Meta*:

managed=True


 class *PostComment*(models.Model):

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

postid = models.ForeignKey(Post)

comment = models.CharField(max_length=4000)

datetime = models.DateField()

class *Meta*:

  managed=True


 class *PostLike*(models.Model):

id = models.*AutoField*(primary_key=True)

postid = models.ForeignKey(Post)

userid = models.ForeignKey(User)

datetime = models.DateField()

class *Meta*:

 managed=True


 class *UserFriend*(models.Model):

id = models.*AutoField*(primary_key=True)

userid = models.ForeignKey(User)

friendid = models.ForeignKey(User)

datetime = models.DateField()

 class *Meta*:

   managed=True

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


Re: Best Practices Django Questions

2015-01-30 Thread G Z
 class User(models.Model):

 

 id = models.AutoField(primary_key=True) 

 username = models.CharField(max_length=4000) 

 password = models.CharField(max_length=4000) 

 email = models.CharField(max_length=4000) 

 phone = models.CharField(max_length=4000) 

 profile_image = models.FileField() 

 about  = models.CharField(max_length=4000) 

 hometown  = models.CharField(max_length=4000) 

 job  = models.CharField(max_length=4000) 

 score  = models.CharField(max_length=4000) 

 hobbies  = models.CharField(max_length=4000) 

 datetime  = models.DateField() 

 class Meta: 

managed=True 


 

class Message(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 friendid = models.ForeignKey(User) 

 msg  = models.CharField(max_length=4000) 

 subject = models.CharField(max_length=4000) 

 datetime  = models.DateField() 

 class Meta: 

managed=True 


 

class MsgQueue(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 friend = models.CharField(max_length=4000) 

 msg  = models.CharField(max_length=4000) 

 type  = models.CharField(max_length=4000) 

 dest  = models.CharField(max_length=4000) 

 datetime  = models.DateField() 

 class Meta: 

managed=True 


 

class UserCode(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 code  = models.CharField(max_length=4000) 

 datetime  = models.DateField() 

 class Meta: 

managed=True 


 

class Album(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 name  = models.CharField(max_length=4000) 

 imageid = models.ForeignKey(Image) 

 datetime  = models.DateField() 

 class Meta: 

managed=True 


 

class Image(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 image = models.FileField() 

 imgdesc  = models.CharField(max_length=4000) 

 datetime  = models.DateField() 

 class Meta: 

managed=True 

 

class ImageComment(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 imageid = models.ForeignKey(Image) 

 comment = models.CharField(max_length=4000) 

 datetime = models.DateField() 

 class Meta: 

managed=True 


 

class ImageLike(models.Model): 

 id = models.AutoField(primary_key=True) 

 imageid = models.ForeignKey(Image) 

 userid = models.ForeignKey(User) 

 datetime = models.DateField() 

 class Meta: 

managed=True 


 

class Post(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 message = models.CharField(max_length=4000) 

 image = models.FileField() 

 embed_link  = models.CharField(max_length=4000) 

 liked_count  = models.CharField(max_length=4000) 

 datetime = models.DateField() 

 class Meta: 

managed=True 


 

class PostComment(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 postid = models.ForeignKey(Post) 

 comment = models.CharField(max_length=4000) 

 datetime = models.DateField() 

 class Meta: 

managed=True 


 

class PostLike(models.Model): 

 id = models.AutoField(primary_key=True) 

 postid = models.ForeignKey(Post) 

 userid = models.ForeignKey(User) 

 datetime = models.DateField() 

 class Meta: 

managed=True 


 

class UserFriend(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 friendid = models.ForeignKey(User) 

 datetime = models.DateField() 

 class Meta: 

managed=True 


 


 

class UserEnviroment(models.Model): 

 id = models.AutoField(primary_key=True) 

 userid = models.ForeignKey(User) 

 elementid = models.ForeignKey(User) 

 datetime = models.DateField() 

 class Meta: 

managed=True 


 

class EnvElement(models.Model): 

 id = models.AutoField(primary_key=True) 

 elementname = models.CharField(max_length=4000) 

 elementfile = models.FileField() 

 elementcost =  models.CharField(max_length=4000) 

 elementmaturetime = models.CharField(max_length=4000) 

 elementposition = models.CharField(max_length=4000) 

 datetime = models.DateField() 

 class Meta: 

managed=True





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


Best Practices Model Design

2015-01-30 Thread G Z
 

Hello, I'm in the design stages of a site that I'm building. It is going to 
be a basic social media site for a game I'm designing in unity. I'm not 
entirely sure how to do some of the things I want to in Django. Thus, my 
first question is generally best practices question as well as a how do I 
do this question.


Qustion #1: How do I set up my models field so that when a user uploads an 
image to a filefield it attaches the users name to the file that is being 
uploaded? Should I do this in the view or in the database?


Question #2: Examine my model design and tell me what I can do better, if 
I'm missing anything etc. I'm new to django so go easy. I didn't do the def 
and functions and class stuff just the over all structure. If it would be 
better if I posted that let me know and I will.


Question#3 How do I make the page when a user logs in resolve to his 
username, and how do I use the username as the url so when you click on a 
list of friends it uses that friends username as the url for their profile 
and resolves to thier page, a quick overview on the best way to do this 
would be just fine. Just point me and kinda explain the theory and I'm sure 
I can figure out the rest. 


Please just help me think of things I need to worry about design with 
django im just starting and I dont have a good base to go on.
class User(models.Model):

 


id = models.AutoField(primary_key=True)

username = models.CharField(max_length=4000)

password = models.CharField(max_length=4000)

email = models.CharField(max_length=4000)

phone = models.CharField(max_length=4000)

profile_image = models.FileField()

about  = models.CharField(max_length=4000)

hometown  = models.CharField(max_length=4000)

job  = models.CharField(max_length=4000)

score  = models.CharField(max_length=4000)

hobbies  = models.CharField(max_length=4000)

datetime  = models.DateField()

 class Meta:

managed=True 


 

class Message(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

friendid = models.ForeignKey(User)

msg  = models.CharField(max_length=4000)

subject = models.CharField(max_length=4000)

datetime  = models.DateField()

 class Meta:

managed=True 

class MsgQueue(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

friend = models.CharField(max_length=4000)

msg  = models.CharField(max_length=4000)

type  = models.CharField(max_length=4000)

dest  = models.CharField(max_length=4000)

datetime  = models.DateField()

 class Meta:

managed=True 

class UserCode(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

code  = models.CharField(max_length=4000)

datetime  = models.DateField()

 class Meta:

managed=True 

class Album(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

name  = models.CharField(max_length=4000)

imageid = models.ForeignKey(Image)

datetime  = models.DateField()

 class Meta:

managed=True 

class Image(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

image = models.FileField()

imgdesc  = models.CharField(max_length=4000)

datetime  = models.DateField()

 class Meta:

managed=True 

 

class ImageComment(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

imageid = models.ForeignKey(Image)

comment = models.CharField(max_length=4000)

datetime = models.DateField()

 class Meta:

managed=True 


 

class ImageLike(models.Model): 


id = models.AutoField(primary_key=True)

imageid = models.ForeignKey(Image)

userid = models.ForeignKey(User)

datetime = models.DateField()

 class Meta:

managed=True 


 

class Post(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

message = models.CharField(max_length=4000)

image = models.FileField()

embed_link  = models.CharField(max_length=4000)

liked_count  = models.CharField(max_length=4000)

datetime = models.DateField()

 class Meta:

managed=True 


 

class PostComment(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

postid = models.ForeignKey(Post)

comment = models.CharField(max_length=4000)

datetime = models.DateField()

 class Meta:

managed=True 


 

class PostLike(models.Model): 


id = models.AutoField(primary_key=True)

postid = models.ForeignKey(Post)

userid = models.ForeignKey(User)

datetime = models.DateField()

 class Meta:

managed=True 


 

class UserFriend(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

friendid = models.ForeignKey(User)

datetime = models.DateField()

 class Meta:

managed=True 


 


 

class UserEnviroment(models.Model): 


id = models.AutoField(primary_key=True)

userid = models.ForeignKey(User)

elementid 

Changing many-to-many using Admin Site never calls post_remove Signal

2015-01-30 Thread Tobias Dacoir
I have a many-to-many relationship which the Admin can change using the 
Admin Site. I use a ModelAdmin.filter_horizontal, but even with the default 
widget it's the same.

I registered a receiver when m2m_changed, however it always only calls: 
pre_clear, post_clear, pre_add, post_add, in that order. 

Now for post_add I have code to execute, to create new objects in the 
database, however when a value is removed from this many-to-many field, I 
need to delete some objects. Since pre_remove is never called, I can't tell 
which value was removed and I'm unable to find out which objects to delete.

Is there a way to modify the Admin page to actually call remove / add on 
the Model? Or I need another way to find out which value was removed.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2b9b7689-ded9-4e7a-88c5-5775e70268f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Changing many-to-many using Admin Site never calls post_remove Signal

2015-01-30 Thread Tobias Dacoir
not very nice, and probably not pythonic (still learning) but now I added 
another two for loops to find old references and delete them:
if action == "post_add":
if isinstance(instance, Database):
# then update pairs
for a in instance.audioData():
for q in instance.questions.all():
pair = AudioQuestionPair.objects.get_or_create(audioData
=a, question=q, database=instance)
for choice in q.get_choices():
answer = Answer.objects.get_or_create(body=choice, 
audioQuestionPair=pair[0])
# check for removed questions and delete pairs
pairs = AudioQuestionPair.objects.filter(database=instance)
toDelete = []
for pair in pairs:
if pair.question not in instance.questions.all():
toDelete.append(pair)
for item in toDelete:
item.delete()



On Friday, January 30, 2015 at 9:44:29 PM UTC+1, Tobias Dacoir wrote:
>
> I have a many-to-many relationship which the Admin can change using the 
> Admin Site. I use a ModelAdmin.filter_horizontal, but even with the default 
> widget it's the same.
>
> I registered a receiver when m2m_changed, however it always only calls: 
> pre_clear, post_clear, pre_add, post_add, in that order. 
>
> Now for post_add I have code to execute, to create new objects in the 
> database, however when a value is removed from this many-to-many field, I 
> need to delete some objects. Since pre_remove is never called, I can't tell 
> which value was removed and I'm unable to find out which objects to delete.
>
> Is there a way to modify the Admin page to actually call remove / add on 
> the Model? Or I need another way to find out which value was removed.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/83eb139a-3732-4986-ad8a-12e36e9c8c1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django web hosts in Canada

2015-01-30 Thread jogaserbia
Hi All,

Thanks for the ideas.  I'll consider the suggestions.

Ivan

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f9862c63-ed67-44e1-80cf-4606221f2c3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CSRF verification failed when I use smart phone

2015-01-30 Thread Pouria M
Thanks Zach. 
What are your thoughts after this test? if they match or if they don't match

On Wednesday, January 28, 2015 at 9:46:23 PM UTC-8, Zach Borboa wrote:
>
> For anyone trying to debug this issue, you may want to print out the 
> variable using {{ csrf_token }} as well as using {% csrf_token %} on the 
> form to verify the token is correct.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/070eea6d-3318-4d97-b946-2510919c3c41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Practices Model Design

2015-01-30 Thread Tobias Dacoir
Hi,

I'm quite new to Django myself. I doubt anyone is going through your whole 
Models File. You should have at least copy & pasted it from some kind of 
IDE to preserve the indention level.

As for your other questions about the url to user-/profilename, have you 
looked at the tutorial: 
https://docs.djangoproject.com/en/1.7/intro/tutorial03/
There the urls.py is explained. In their example question_id is used, but I 
bet you could use something else as well. Or go with the user_id (that's 
what I did, of course doesn't look so pretty).

And about the file upload - I didn't rename the files yet, but it's good 
practice, so I looked up the documentation and apparently you can overwrite 
the filename. I will have to try this out too later: 
https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.FileField

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8ba0d61e-4374-4391-b7c9-45b49253499d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: using Django on an existing mysql schema

2015-01-30 Thread Russell Keith-Magee
On Sat, Jan 31, 2015 at 3:14 AM, Tobias Dacoir  wrote:

> I'm certainly no Django expert, but I'm not sure if you can use the orm
> and an already existing database.
>

Yes, you absolutely can. There's even a management command (inspectdb) to
help write the wrapper models, and a Meta flag (managed=False) to make sure
the migration tools won't touch those models.


> However the documentation states that you can write all queries yourself,
> essentially not using the orm. However if you do that, I'm wondering why
> you want to use Django at all?
>

Because Django has a lot more than just an ORM. There's a forms layer,
authentication tools, and lots more.


> And pushing business logic into the database sounds like bad design to me
> (model and controller should be decoupled in MVC like patterns).
>

It depends what logic you're talking about, and what other tools will be
using the same database. "MVC" separation like you are describing assumes
that the Controller is shared; if you have to re-implement the controller
in two languages, then there's a very strong argument to push some of the
controller's functionality into the database.

Yours,
Russ Magee %-)

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq849XqUqr_HqLBV6x8xcr%3Da9dU5ipT_V4tLyEK%3DgzZCJLqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: using Django on an existing mysql schema

2015-01-30 Thread Russell Keith-Magee
On Fri, Jan 30, 2015 at 10:47 PM, William Muriithi <
william.murii...@gmail.com> wrote:

> ‎Hello,
>
> I am new to Django and planning to use it for a project I have in mind. I
> am strong in mysql, but not too good in developing. In fact, the secondary
> purpose of this project is to improve my python development skills.
>
> With such a background, I went about doing my data modeling and then set
> up views on top to de normalize the underlying schema and pushing most of
> the business logic in mysql. I want to use Django mainly to insert and
> display, which increases the chance of success with few bugs.
>
> Problem is, with Django, it seems things are done the other way around.
> After playing with it, I noticed it changes the keys from unsigned to
> signed, something I feal is bad from database point of view. It converted
> enum to char, which to me is less appealing. In short, I don't like the
> change its introducing. ‎
>
> My question is, can one use Django with an existing database without
> getting in trouble with the framework? I believe this has to be possible
> somehow as most companies work from data backwards. Would appreciate a good
> advice on how you guys and girls went‎ about using Django from existing
> schema. Or a Django book that take that perspective. The once I have read
> advice me to leave database work to orm.
>

Yes, you can. Django's ORM is there to make your life easier, but there's
no requirement that you use it to create your tables, or even to execute
queries. There's an inspectdb management command to help build wrapper
models for your database; but if you want, you can avoid the ORM entirely,
and use raw database cursors to talk directly to the database.

Of course, if you do this, you're going to miss out on at least some of the
power of Django.

For example, Django has a forms library, which is quite powerful. You can
use it without using Django's ORM. However, if you *are* using Django's
ORM, you can use ModelForms, which is a way to automatically generate a
form for a model.

You're also going to miss out on the community of apps that are out there
to help you get functionality running easily. For example, if you don't
have Django ORM models, then Django's admin interface wont work. A lot of
the power of Django is that it has a good "meta" understanding of the data
in the database; if you take that away, then the functionality that relies
on it obviously wont work.

There's nothing inherently wrong with this - you can code everything
yourself if you want and treat Django as little more than a request routing
library. The only problems you're going to experience are related to the
fact that documentation out there will generally assume that you're using
Django models, not rolling your own. My only concern is that this might
leave you with an odd perception of the capabilities of Django.

Yours,
Russ Magee %-)

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq84-Vf5iTNxH-B2FGnS1sTxT-UA0V%3D4o5axLw_K%2BGpEf%3Dtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: CSRF verification failed when I use smart phone

2015-01-30 Thread Zach Borboa
What you want to compare is the expected token value and the token value 
the view received (via POST, PUT, DELETE, etc.). These values need to 
match. Printing out the token via {{ csrf_token }} in the template will 
show you the token that the view will receive when the form is submitted. 
This submitted value needs to match the value in the cookie named csrftoken.


On Friday, January 30, 2015 at 1:59:45 PM UTC-8, Pouria M wrote:
>
> Thanks Zach. 
> What are your thoughts after this test? if they match or if they don't 
> match
>
> On Wednesday, January 28, 2015 at 9:46:23 PM UTC-8, Zach Borboa wrote:
>>
>> For anyone trying to debug this issue, you may want to print out the 
>> variable using {{ csrf_token }} as well as using {% csrf_token %} on the 
>> form to verify the token is correct.
>>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e7d8ec73-4fc1-44bf-9424-77edb20d4bb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CSRF verification failed when I use smart phone

2015-01-30 Thread Zach Borboa


Here's an example of the csrf cookie value obtained by typing 
document.cookie in the javascript console.



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3879ce91-fa33-4e6f-a57b-d51abf6052e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Do Signals block Django process?

2015-01-30 Thread Babatunde Akinyanmi
On 30 Jan 2015 17:13, "Tobias Dacoir"  wrote:
>
> I just added django-badges to my project. Basically it can award Badges
if Users fullfill certain requirements. For this, everytime I call
user.save() django-badges receives the post_save() signal and starts
checking.
>
> Now my project is similar to an online quiz, where users submit forms to
answer questions. Right now I only have tested it locally and I'm not sure
how to simulate multiple users accessing the page at the same time.
>
> When later run on production in combination with a webserver, will Django
spawn a new thread for each connection / user? Or will there be only one
thread, so if two users are accessing the website, the 2nd has to wait
until the request from the first user is processed?
>

Django is single threaded but the web server can create multiple instances
of your application.

> Also what about my signal to process the badges. If I have a function
that calls user.save(), which then signals to the badges module, will the
execution of the original function stop until the signal has been processed
or not?
>
> def myView(request):
>do_something()
>request.user.save()
># signal emitted
># ...
>render(view)
>
> So in this case, will the view be rendered immediately or only after the
receiver for the signal has finished doing it's work? In my case I don't
really need it to be asynchronous as long as the badge checking is fast
enough and doesn't block the website for other users.
>

The view will return after the receiver has finished its work. But are you
doing any slow queries? I ask because you might be over engineering your
work.

A good place to start is to benchmark your queries using a tool like
django-debug-toolbar. With that you can know exactly how long it takes one
user to query your database and then use that to estimate for more users.

> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f3b2f9dd-4681-48a1-8d49-79f73d45d0eb%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BWjgXPiaV7iFGnFZRiQCNBv_hNypGO%2BewyOxHkLcfOfQ-Vjtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Practices Django Questions

2015-01-30 Thread Babatunde Akinyanmi
On 30 Jan 2015 21:03, "G Z"  wrote:
>
> Hello, I'm in the design stages of a site that I'm building. It is going
to be a basic social media site for a game I'm designing in unity. I'm not
entirely sure how to do some of the things I want to in Django. Thus, my
first question is generally best practices question as well as a how do I
do this question.
>
> Qustion #1: How do I set up my models field so that when a user uploads
an image to a filefield it attaches the users name to the file that is
being uploaded? Should I do this in the view or in the database?
>

Database. You can adjust the name after validation and just before it is
saved to the database so you can just override the save method.

> Question #2: Examine my model design and tell me what I can do better, if
I'm missing anything etc. I'm new to django so go easy. I didn't do the def
and functions and class stuff just the over all structure. If it would be
better if I posted that let me know and I will.
>
> Question#3 How do I make the page when a user logs in resolve to his
username, and how do I use the username as the url so when you click on a
list of friends it uses that friends username as the url for their profile
and resolves to thier page, a quick overview on the best way to do this
would be just fine. Just point me and kinda explain the theory and I'm sure
I can figure out the rest.
>
> Please just help me think of things I need to worry about design with
django im just starting and I dont have a good base to go on.
>
>
> User
>
> id = models.AutoField(primary_key=True)
>
> username = models.CharField(max_length=4000)
>
> password = models.CharField(max_length=4000)
>
> email = models.CharField(max_length=4000)
>
> phone = models.CharField(max_length=4000)
>
> profile_image = models.FileField()
>
> about = models.CharField(max_length=4000)
>
> hometown = models.CharField(max_length=4000)
>
> job = models.CharField(max_length=4000)
>
> score = models.CharField(max_length=4000)
>
> hobbies = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Album
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> name = models.CharField(max_length=4000)
>
> imageid = models.ForeignKey(Image)
>
> datetime = models.DateField()
>
>
> Image
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> image = models.FileField()
>
> imgdesc = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
> Image_Comment
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> imageid = models.ForeignKey(Image)
>
> comment = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Image_Likes
>
> id = models.AutoField(primary_key=True)
>
> imageid = models.ForeignKey(Image)
>
> userid = models.ForeignKey(User)
>
> datetime = models.DateField()
>
>
> Post
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> message = models.CharField(max_length=4000)
>
> image = models.FileField()
>
> embed_link = models.CharField(max_length=4000)
>
> liked_count = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Post_Comment
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> postid = models.ForeignKey(Post)
>
> comment = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Post_User_Likes
>
> id = models.AutoField(primary_key=True)
>
> postid = models.ForeignKey(Post)
>
> userid = models.ForeignKey(User)
>
> datetime = models.DateField()
>
>
> User_Friends
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> friendid = models.ForeignKey(User)
>
> blocked = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Reported
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> friendid = models.ForeignKey(User)
>
> comment = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/71830c67-c98c-4e38-95f8-235f7c1b9d81%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
h

Re: How to get hold of a session after getting signaled?

2015-01-30 Thread Vijay Khemlani
As far as I can tell on the project source, the only place the
"badge_awarded" signal is triggered is in the "award_to" method in the
Badge class, which does not handle a request object.

If you are calling something like "badge.award_to(user)" in one of your
views, then you can modify the request response immediately after, without
using the signal.

On Fri, Jan 30, 2015 at 1:19 PM, Tobias Dacoir  wrote:

> I'm using django-badges in my project which can emit a signal when a user
> is awarded a badge. I was able to implemented a receiver function, however
> the output is the following:
>
> signals.py (from badges):
> import django.dispatch
>
> badge_awarded = django.dispatch.Signal(providing_args=['user', 'badge'])
>
>
>
> my receiver function test:
>
> from badges.signals import badge_awarded
> @receiver(badge_awarded)
> def do_something_after_badge_awarded(sender, user, badge, **kwargs):
> print "Badge Signal received"
> print sender # 
> print user # user object
> print badge # badge object
> print kwargs
>
>
>
> and the output was:
> Badge Signal received
> 
> player1
> Test Badge 2
> {'signal': }
>
>
> I want to add a message to the request, to notify or show the user that he
> earned a badge. Is it possible someone get hold of the request? I can
> freely modify the original source code from django-badges. Currently it's
> invoked by post_save() on a model instance. So I doubt I can get the
> request from there.
>
> I found a solution to add another 3rd party app which is called
> django-notification, but I don't want to add too many apps to my project.
> Another solution might be to just set some variable in the database and in
> my view to query this variable - however that will also cost performance
> and two database hits.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5e8f655c-8385-46aa-94ae-2c5baef2034a%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1Q8cCtBgmsAQV%2BN_o3-5i-%2BrACxMXJXX3Gc%2BQhbtqkQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


admin site questions

2015-01-30 Thread Mike
I'm building a simple CRUD application to hold some data for our research 
group.  After 2 hours I have the basic functionality working using the 
admin site only and no custom views.  I just need to figure out if I can go 
ahead and deploy it using the admin site as the main user interface. So, my 
questions are:

1) Is it ok to use the admin site as the main interface to the project? It 
will not be public facing and will be used by 4-5 people.

2) On the admin page, 'Select [model] to change' can I have those links 
point to a read only view of the model data and then have that page link to 
an editable view? I'm thinking that having an extra step will help to 
prevent accidental updates.


Thanks
Mike

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a83b7ad7-d353-4770-876b-18760ea3b6b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


using celery with django.

2015-01-30 Thread sarfaraz ahmed
I am experimenting with celery with django and i am using windows 7 os on 
my machine.

Here is outcome... so far.

I added sample app to my project and added tasks.py to my app.

tasks.py 

from models import SampleCount
from celery import task

@task()
def add_to_count():
try:
sc=SampleCount.objects.get(pk=1)
except:
sc=SampleCount()
sc.counter=sc.counter+1
sc.save()

 --
 models.py 

from django.db import models

# Create your models here.
class SampleCount(models.Model):
counter = models.IntegerField(default=0)


def __int__(self):
return self.counter
---
settings.py
--

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'User_Registration',
'Location_Management',
'Drop_Slot_Management',
'django_extensions',
'djcelery',
'kombu.transport.django',
'sample',
)

BROKER_URL = "django://"

-
Here is what I am doing I am running manage.py shell
importing the model and running the add_to_count() which adds to counter 
field. 

I run the celeryd from manage.py celeryd. it runs without error

when i run add_to_count.delay().  I get following error in celeryd running 
prompt. 
  uuid, retval, SUCCESS, request=task_request,
File 
"C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File 
"C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File 
"C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File 
"C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File 
"C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File 
"C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, 
self.get_met
))
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File 
"C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache