Re: reqquest.user is not defined

2011-07-21 Thread vikalp sahni
If There is no user request.user holds. AnonymousUser Object.

if you user request.user.is_authenticated() it should give False in case
user if not logged_in, and you can load your page accordingly.

Regards,
//Vikalp


On Thu, Jul 21, 2011 at 11:52 AM, bahare hoseini wrote:

> hi there,
> i've installed *AuthenticationMiddleWare *& *SessionMidleWare *in
> MIDDLEWARE_CLASSES in setting.py,
> but wherever i use (request.user) my web page such as log_in page,is loaded
> as if it doesn't know request.user => there is no limit to access pages!!
>
> could you please tell me why?
>
> thanks,
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: reqquest.user is not defined

2011-07-21 Thread nicolas HERSOG
Few things, can you retrieve all the user data in your pages ? If not you
should look to  httpRequestContext
https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/ and use
render_to_response


On Thu, Jul 21, 2011 at 9:15 AM, vikalp sahni  wrote:

> If There is no user request.user holds. AnonymousUser Object.
>
> if you user request.user.is_authenticated() it should give False in case
> user if not logged_in, and you can load your page accordingly.
>
> Regards,
> //Vikalp
>
>
> On Thu, Jul 21, 2011 at 11:52 AM, bahare hoseini wrote:
>
>> hi there,
>> i've installed *AuthenticationMiddleWare *& *SessionMidleWare *in
>> MIDDLEWARE_CLASSES in setting.py,
>> but wherever i use (request.user) my web page such as log_in page,is
>> loaded as if it doesn't know request.user => there is no limit to access
>> pages!!
>>
>> could you please tell me why?
>>
>> thanks,
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: problem with BooleanField form

2011-07-21 Thread Daniel Roseman
On Thursday, July 21, 2011 4:00:55 AM UTC+1, ed wrote:
>
> I'm using the following javascript, so I can't check the HTML, can I? 
> How would I go about debugging this? 
>
> function bookmark_save() { 
> var item = $(this).parent(); 
> var data = { 
> url: item.find("#id_url").val(), 
> title: item.find("#id_title").val(), 
> tags: item.find("#id_tags").val() 
> }; 
> $.post("/save/?ajax", data, function (result) { 
> if (result != "failure") { 
> item.before($("li", result).get(0)); 
> item.remove(); 
> $("ul.bookmarks .edit").click(bookmark_edit); 
> } 
> else { 
> alert("Failed to validate bookmark before saving."); 
> } 
> }); 
> return false; 
> } 
>
> function bookmark_edit() { 
> var item = $(this).parent(); 
> var url = item.find(".title").attr("href"); 
> item.load( 
> "/save/?ajax&url=" + encodeURIComponent(url), 
> null, 
> function () { 
> $("#save-form").submit(bookmark_save); 
> } 
> ); 
> return false; 
> } 
>
> $(document).ready(function () { 
> $("ul.bookmarks .edit").click(bookmark_edit); 
> }); 
>
>  
But surely the problem is that you haven't supplied a value for  `share` in 
your Ajax data.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/mjrC6FcpQJwJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is there a way to insert data from a csv file into my database?

2011-07-21 Thread Shawn Milochik
Please search the archive of this list. This exact thing has been addressed
in detail.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django-admin inspectdb does not detect NULL columns for PostgreSQL database

2011-07-21 Thread Ricardo L. Dani
Hi everyone,

I have the same problem of this ticket from django trac:
https://code.djangoproject.com/ticket/7783

The PostgreSQL database introspection does not detect NULL columns,
cursor.description does not return the null_ok field, so database
introspection does not add null=True to column definitions. The
is_nullable column in information_schema.columns does contain this
information, however.

A patch was subimitted, but i can't apply this 'cause the version of
django that's the patch was appliend is different to 1.3 (the version
i use).

Somebody knows what version of django this patch is applied? Or a
other way to solve this problem?

Regards

-- 
Ricardo Lapa Dani

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Manually ordering items in relation to siblings

2011-07-21 Thread Andre Terra
Shameless bump.

Althought the original post is long, I assure you it's easy to understand.

Any suggestions?


Cheers,
André Terra


On Tue, Jul 19, 2011 at 2:58 PM, Andre Terra  wrote:

> Hello, everyone
>
> Assume the following models (dpaste.com [1]):
>
> class Account(models.Model):
> """
> Account model for categorizing entries from each SAP import,
> and eventually sorting, grouping, filtering data.
>
> """
> code = models.CharField(max_length=255, primary_key=True)
>
> group = models.ForeignKey('AccountGroup', blank=True, null=True,
>   related_name='groups')
>
> description = models.CharField(max_length=512, blank=True, null=True)
>
>
> class AccountGroup(models.Model):
> name = models.CharField(max_length=512, blank=True, null=True,
> verbose_name=_('Name'))
>
> parent = models.ForeignKey('AccountGroup', blank=True, null=True,
>related_name='children')
>
> is_subgroup = models.BooleanField(default=False, editable=False)
>
> def save(self, *args, **kwargs):
> self.is_subgroup = False
>
> if self.parent is not None:
> self.is_subgroup = True
>
> return super(AccountGroup, self).save(*args, **kwargs)
>
> I would like to be able to manually specify an order for AccountGroups in
> relation to their siblings, so that I can have a final result of something
> like the following pic (which describes a set of groups and accounts, with
> the latter being the rightmost, M0-format codes.
>
> http://img200.imageshack.us/img200/9423/groupsandaccounts.png
>
>
> As you can see from the picture, accounts can be located under any number
> of groups, and neither Accounts nor AccountGroups are not sorted naturally.
>
> Short of using something like django-treebeard[3], how can I write a
> solution for this use case?
>
> Thanks in advance for all your help!
>
>
> Cheers,
> André Terra
>
>
> [1] http://dpaste.com/hold/571566/
> [2]
> https://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparatedintegerfield
> [3] https://tabo.pe/projects/django-treebeard/docs/1.52/
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Manually ordering items in relation to siblings

2011-07-21 Thread Daniel Roseman

>
> On Tue, Jul 19, 2011 at 2:58 PM, Andre Terra  wrote:
>
>> Hello, everyone
>>
>> Assume the following models (dpaste.com [1]):
>>
>> class Account(models.Model):
>> """
>> Account model for categorizing entries from each SAP import,
>> and eventually sorting, grouping, filtering data.
>> 
>> """
>> code = models.CharField(max_length=255, primary_key=True)
>> 
>> group = models.ForeignKey('AccountGroup', blank=True, null=True,
>>   related_name='groups')
>> 
>> description = models.CharField(max_length=512, blank=True, null=True)
>> 
>> 
>> class AccountGroup(models.Model):
>> name = models.CharField(max_length=512, blank=True, null=True,
>> verbose_name=_('Name'))
>> 
>> parent = models.ForeignKey('AccountGroup', blank=True, null=True,
>>related_name='children')
>> 
>> is_subgroup = models.BooleanField(default=False, editable=False)
>> 
>> def save(self, *args, **kwargs):
>> self.is_subgroup = False
>> 
>> if self.parent is not None:
>> self.is_subgroup = True
>> 
>> return super(AccountGroup, self).save(*args, **kwargs)
>>
>> I would like to be able to manually specify an order for AccountGroups in 
>> relation to their siblings, so that I can have a final result of something 
>> like the following pic (which describes a set of groups and accounts, with 
>> the latter being the rightmost, M0-format codes.
>>
>> http://img200.imageshack.us/img200/9423/groupsandaccounts.png
>>
>>
>> As you can see from the picture, accounts can be located under any number 
>> of groups, and neither Accounts nor AccountGroups are not sorted naturally.
>>
>> Short of using something like django-treebeard[3], how can I write a 
>> solution for this use case?
>>
>> Thanks in advance for all your help!
>>
>>
>> Cheers,
>> André Terra
>>
>>
>> [1] http://dpaste.com/hold/571566/
>> [2] 
>> https://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparatedintegerfield
>> [3] https://tabo.pe/projects/django-treebeard/docs/1.52/
>>
>>
>
Well, a pre-order algorithm like MPTT - as provided by django-treebeard or 
django-mptt - *is* the way to go here. You don't say why you don't want to 
go down that route - what's your objection?
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/llCUKidcbscJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Manually ordering items in relation to siblings

2011-07-21 Thread Andre Terra
django-mptt looks great, I totally forgot it existed. It seems I visited the
project's website ages ago, but I honestly don't recall it.

As for django-treebeard, I didn't like the API, docs and examples. Actually,
the examples don't even work, so I was a little worried about using it.

I'll give mptt a whirl, thanks a billion.


Cheers,
AT

On Thu, Jul 21, 2011 at 10:12 AM, Daniel Roseman wrote:

> On Tue, Jul 19, 2011 at 2:58 PM, Andre Terra  wrote:
>>
>>> Hello, everyone
>>>
>>> Assume the following models (dpaste.com [1]):
>>>
>>> class Account(models.Model):
>>> """
>>> Account model for categorizing entries from each SAP import,
>>> and eventually sorting, grouping, filtering data.
>>>
>>> """
>>> code = models.CharField(max_length=**255, primary_key=True)
>>>
>>> group = models.ForeignKey('**AccountGroup', blank=True, null=True,
>>>   related_name='groups')
>>>
>>> description = models.CharField(max_length=**512, blank=True,
>>> null=True)
>>>
>>>
>>> class AccountGroup(models.Model):
>>> name = models.CharField(max_length=**512, blank=True, null=True,
>>> verbose_name=_('Name'))
>>>
>>> parent = models.ForeignKey('**AccountGroup', blank=True, null=True,
>>>related_name='children')
>>>
>>> is_subgroup = models.BooleanField(default=**False, editable=False)
>>>
>>> def save(self, *args, **kwargs):
>>> self.is_subgroup = False
>>>
>>> if self.parent is not None:
>>> self.is_subgroup = True
>>>
>>> return super(AccountGroup, self).save(*args, **kwargs)
>>>
>>> I would like to be able to manually specify an order for AccountGroups in
>>> relation to their siblings, so that I can have a final result of something
>>> like the following pic (which describes a set of groups and accounts, with
>>> the latter being the rightmost, M0-format codes.
>>>
>>> http://img200.imageshack.us/**img200/9423/groupsandaccounts.**png
>>>
>>>
>>> As you can see from the picture, accounts can be located under any number
>>> of groups, and neither Accounts nor AccountGroups are not sorted naturally.
>>>
>>> Short of using something like django-treebeard[3], how can I write a
>>> solution for this use case?
>>>
>>> Thanks in advance for all your help!
>>>
>>>
>>> Cheers,
>>> André Terra
>>>
>>>
>>> [1] http://dpaste.com/hold/571566/
>>> [2] https://docs.djangoproject.**com/en/dev/ref/models/fields/#**
>>> commaseparatedintegerfield
>>> [3] 
>>> https://tabo.pe/projects/**django-treebeard/docs/1.52/
>>>
>>>
>>
> Well, a pre-order algorithm like MPTT - as provided by django-treebeard or
> django-mptt - *is* the way to go here. You don't say why you don't want to
> go down that route - what's your objection?
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/llCUKidcbscJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Problem with relationships in models

2011-07-21 Thread Oliver Schmidt
I'm trying to write my first django app, so maybe my problem is stupid. 
But I have problems in using relationships in my models.

My models.py looks like this:

   # -*- coding: utf-8 -*-
   from django.db import models
   from django.contrib.auth.models import User
   import datetime

   class Kalender(models.Model):
name = models.CharField("Kalendername", max_length=100)
description = models.TextField("Beschreibung")

class Meta:
verbose_name_plural = "Kalender"

   class Termin(models.Model):
in_calendar = models.ForeignKey(Kalender)
name = models.CharField("Terminname", max_length=100)
date = models.DateTimeField("Datum und Uhrzeit")
description = models.TextField("Beschreibung")

def is_today(self):
return self.date.date() == datetime.date.today()

is_today.short_description = "Termin findet heute statt?"

participants = models.ManyToManyField(User)

class Meta:
verbose_name_plural = "Termine"



Syncdb creates the tables without errors.
Next I configured the admin to include both classes:

   from kalender.models import *
   from django.contrib import admin

   admin.site.register(Kalender)
   admin.site.register(Termin)


The admin-interface for the class Kalender works fine, but Termin 
produces errors:



 OperationalError at /admin/kalender/termin/

(1054, "Unknown column 'kalender_termin.in_calendar_id' in 'field list'")

Traceback:

Environment:


Request Method: GET
Request URL:http://127.0.0.1:8000/admin/kalender/termin/

Django Version: 1.3
Python Version: 2.7.0
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'chor.poll',
 'chor.kalender',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in 
get_response
  111. response = callback(request, *callback_args, 
**callback_kwargs)
File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py" 
in wrapper
  307. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py" in 
_wrapped_view
  93. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/views/decorators/cache.py" 
in _wrapped_view_func
  79. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in 
inner
  197. return view(request, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py" in 
_wrapper
  28. return bound_func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py" in 
_wrapped_view
  93. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py" in 
bound_func
  24. return func(self, *args2, **kwargs2)
File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py" 
in changelist_view
  1159. 'selection_note': _('0 of %(cnt)s selected') % {'cnt': 
len(cl.result_list)},
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in 
__len__
  82. self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in 
iterator
  273. for row in compiler.results_iter():
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" 
in results_iter
  680. for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" 
in execute_sql
  735. cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/util.py" in 
execute
  34. return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py" 
in execute
  86. return self.cursor.execute(query, args)
File "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py" in execute
  174. self.errorhandler(self, exc, value)
File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py" in 
defaulterrorhandler
  36. raise errorclass, errorvalue

Exception Type: OperationalError at /admin/kalender/termin/
Exception Value: (1054, "Unknown column 'kalender_termin.in_calendar_id' in 'field 
list'")



_*So what the hell am I doing wrong?
*_/Thanks for help/

--
You received 

Re: import django models without runing the server

2011-07-21 Thread Malcolm Box
On 18 July 2011 15:41, Shawn Milochik  wrote:

> On Mon, Jul 18, 2011 at 10:33 AM, bruno desthuilliers
>  wrote:
> > On Jul 18, 3:33 pm, Alexander Crössmann
> >  wrote:
> >> Hi Malcom,
> >>
> >> I am not sure the management commands are what I want
> >
> > Strange enough, it seems that everyone starts by saying this and ends
> > up writing custom management commands ;)
> >
>
>
> Getting the DJANGO_SETTINGS_MODULE correct is all that's needed. I've
> never created a management command, nor needed to.
>

While it's true you don't *need* to, my experience is it's better to.

Every time I've created a separate script to interact with a Django app, it
has subsequently been broken when I've changed something in the app. Usually
this has gone unnoticed until some inconvenient time.

If you make the script a management command, you have an easy way to build
tests for it right into your app, so that it's impossible (ok, hard) for
changes to break the script without you noticing.

So my advice: if you're actively developing your app, then make any scripts
that need to furtle about with the models management commands.

Malcolm

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Aw: Problem with relationships in models

2011-07-21 Thread Schmidtchen Schleicher
Something went wrong with posting the model, it should be:

# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
import datetime

class Kalender(models.Model):
name = models.CharField("Kalendername", max_length=100)
description = models.TextField("Beschreibung")

class Meta:
verbose_name_plural = "Kalender"

class Termin(models.Model):
in_calendar = models.ForeignKey(Kalender)
name = models.CharField("Terminname", max_length=100)
date = models.DateTimeField("Datum und Uhrzeit")
description = models.TextField("Beschreibung")

def is_today(self):
return self.date.date() == datetime.date.today()

is_today.short_description = "Termin findet heute statt?"

participants = models.ManyToManyField(User)

class Meta:
verbose_name_plural = "Termine"

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/IiaS26VAlVAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with relationships in models

2011-07-21 Thread Malcolm Box
A guess, but are you sure syncdb created the tables? Ie have you checked
using mysql, or manage.py dbshell that the tables are really there?

Syncdb only creates tables for a model the first time it is run - after that
it won't track updates. So if you ran it, then added the relationship, then
ran again you'd get the error your seeing.

If you have no data, just blow away the tables and start again. If you have
data, now is a good time to find out about South (http://south.aeracode.org)

Malcolm


On 21 July 2011 15:34, Schmidtchen Schleicher wrote:

> Something went wrong with posting the model, it should be:
>
>
> # -*- coding: utf-8 -*-
> from django.db import models
> from django.contrib.auth.models import User
> import datetime
>
> class Kalender(models.Model):
> name = models.CharField("Kalendername", max_length=100)
> description = models.TextField("Beschreibung")
>
> class Meta:
> verbose_name_plural = "Kalender"
>
> class Termin(models.Model):
> in_calendar = models.ForeignKey(Kalender)
> name = models.CharField("Terminname", max_length=100)
> date = models.DateTimeField("Datum und Uhrzeit")
> description = models.TextField("Beschreibung")
>
> def is_today(self):
> return self.date.date() == datetime.date.today()
>
> is_today.short_description = "Termin findet heute statt?"
>
> participants = models.ManyToManyField(User)
>
> class Meta:
> verbose_name_plural = "Termine"
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/IiaS26VAlVAJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Malcolm Box
malcolm@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django.contrib.auth.view.login reuse

2011-07-21 Thread Jonas Geiregat
Hello,

I would like to add login fields to each page. But I want to keep it as DRY as 
possible.
 I'm pretty satisfied until now about using django.contrib.auth.views.login 
,but that's just one specific view in my case host.com/login. With a urls.py 
line as: 
(r'^/login/$', 'django.contrib.auth.views.login', {'template_name': 
'myapp/login.html'}),

All this django builtin view does is add stuff to the context of the request 
and render one single template.

My problem now is, can I reuse that view in other views or use it so I can as a 
template context processor, so it's always available ? 
I'm having trouble figuring out which would be the best route to take.

Any advise is welcome,

Regards,

Jonas.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread Valder Gallo

Alexander,

Try use this

#test.py
import os, sys
sys.path.append('../')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

myproject/test.py


On 07/18/2011 09:34 AM, Alexander Crössmann wrote:

Hi,

I want to write a python script that works with django models without
runing the server. My OS ist Ubuntu 10.10.

My skipt looks as follows:

import sys
sys.path.append('/home/myname/python/django_projects/')
sys.path.append('/home/myname/python/')
import settings
from django_projects.codierung.models import *

The settings work fine with testserver and apache but wenn I run the
that skript I geht the following error:

ImportError: Settings cannot be imported, because environment variable
DJANGO_SETTINGS_MODULE is undefined.

What else do I need to define appart from the stuff that is allready in
the settings file? I read the page on settings in the documentation but
that wouldn't help me.

Thanks for any Help!
Alex



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread Jonas Geiregat

> Alexander,
> 
> Try use this
> 
> #test.py
> import os, sys
> sys.path.append('../')
> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
> 
> myproject/test.py
> 


This is a good read on the subject , it presents an elegant solution.

http://superjared.com/entry/django-and-crontab-best-friends/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django.contrib.auth.view.login reuse

2011-07-21 Thread Jonas Geiregat


> Hello,
> 
> I would like to add login fields to each page. But I want to keep it as DRY 
> as possible.
> I'm pretty satisfied until now about using django.contrib.auth.views.login 
> ,but that's just one specific view in my case host.com/login. With a urls.py 
> line as: 
> (r'^/login/$', 'django.contrib.auth.views.login', {'template_name': 
> 'myapp/login.html'}),
> 
> All this django builtin view does is add stuff to the context of the request 
> and render one single template.
> 
> My problem now is, can I reuse that view in other views or use it so I can as 
> a template context processor, so it's always available ? 
> I'm having trouble figuring out which would be the best route to take.

I've figured some stuff out already. Being able to read the django source code 
is such a bless!
I can use the form stored at django.contrib.auth.forms.AuthenticationForm.

Knowing I can easily access the login from I could create my own context 
processor and add it side-wide from there. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Aw: Re: Problem with relationships in models

2011-07-21 Thread Schmidtchen Schleicher
You were right! I resetted the app and now it works

+1

THX

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/dfsjUI6oH7IJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



__init__ got unexpected argument

2011-07-21 Thread shakthi
while executing the following model i got the error message
__init() got an unexpected keyword argument 'maxlength'


from django.db import models

class Author(models.Model):
name=models.CharField(maxlength=20)
city=models.CharField(maxlength=10)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread bruno desthuilliers
On Jul 21, 4:45 pm, Valder Gallo  wrote:
> Alexander,
>
> Try use this
>
> #test.py
> import os, sys
> sys.path.append('../')

This is relative to whatever the current working directory is whenever
the script is called. Very bad idea, will obviously break one day or
another.

The canonical way to know the full path to the script's is
"os.path.abspath(__file__)". Then you just have to use os.path.dirname
to get the script's dir, etc...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: __init__ got unexpected argument

2011-07-21 Thread Alex Hall
The word you want is max_length, not maxlength (note the underscore).
Try changing to max_length and it should run.

On 7/21/11, shakthi  wrote:
> while executing the following model i got the error message
> __init() got an unexpected keyword argument 'maxlength'
>
>
> from django.db import models
>
> class Author(models.Model):
> name=models.CharField(maxlength=20)
> city=models.CharField(maxlength=10)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread bruno desthuilliers
On Jul 21, 4:53 pm, Jonas Geiregat  wrote:
>
> This is a good read on the subject , it presents an elegant solution.
>
> http://superjared.com/entry/django-and-crontab-best-friends/


With the problem that it will use the first module named "settings" in
sys.path, which may *or not* be what you want - here again, current
working directory issues, as well as not being able to use an
alternate settings (as you could with django-admin.py).

I maintain, from experience, that custom commands are the simplest,
safest and most flexible solution.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: __init__ got unexpected argument

2011-07-21 Thread sakthi vel
Thank you!

On Thu, Jul 21, 2011 at 8:52 PM, Alex Hall  wrote:

> The word you want is max_length, not maxlength (note the underscore).
> Try changing to max_length and it should run.
>
> On 7/21/11, shakthi  wrote:
> > while executing the following model i got the error message
> > __init() got an unexpected keyword argument 'maxlength'
> >
> >
> > from django.db import models
> >
> > class Author(models.Model):
> > name=models.CharField(maxlength=20)
> > city=models.CharField(maxlength=10)
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
> >
> >
>
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread Javier Guerra Giraldez
On Thu, Jul 21, 2011 at 10:27 AM, bruno desthuilliers
 wrote:
> I maintain, from experience, that custom commands are the simplest,
> safest and most flexible solution.

same here

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread Andre Terra
>
> On Jul 21, 4:53 pm, Jonas Geiregat  wrote:
> >
> > This is a good read on the subject , it presents an elegant solution.
> >
> > http://superjared.com/entry/django-and-crontab-best-friends/
>
>
> With the problem that it will use the first module named "settings" in
> sys.path, which may *or not* be what you want - here again, current
> working directory issues, as well as not being able to use an
> alternate settings (as you could with django-admin.py).
>

FWIW, one could always use sys.path.insert(0, path)


AT

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread Andre Terra
Nevermind, I thought you were referring to the previously sys.path.append()
method.


Regards,
AT

On Thu, Jul 21, 2011 at 1:13 PM, Andre Terra  wrote:

> On Jul 21, 4:53 pm, Jonas Geiregat  wrote:
>> >
>> > This is a good read on the subject , it presents an elegant solution.
>> >
>> > http://superjared.com/entry/django-and-crontab-best-friends/
>>
>>
>> With the problem that it will use the first module named "settings" in
>> sys.path, which may *or not* be what you want - here again, current
>> working directory issues, as well as not being able to use an
>> alternate settings (as you could with django-admin.py).
>>
>
> FWIW, one could always use sys.path.insert(0, path)
>
>
> AT
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Database Design Question

2011-07-21 Thread newtodjango
Hi. I have a question about writing normalized models. I began writing
an app that has non-normalized tables, and would like to rewrite it
with a normalized design.

I have non-normalized legacy tables like this without foreign keys or
many-to-many relationships, which I would like to have.

Contract

 id contract_id   product_id rebate_pct
  1 1  1230.22
  2 1  1240.30

Note repeating contract_id above. Each contract may have a different
number of products associated with it
Each product in the Contract table in turn has its own rebate_pct.

Product

id   product   product_name quantity_per_p
product_description
1  123name1
20   some_desc1
2  124name2
20   some_desc2

I'd like to define the Product model such that it has the unique
contract_id per row, but each contract_id should have the associated
multiple products and their rebate percentages.

I started with:

class Contract(models.Model):
contract_id = models.IntegerField(unique=True)
product = models.ManyToManyField(Product)

but don't know about rebate_pct. Should it be a ManyToMany into a
special rebates table?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



changing how, or if, model fields display

2011-07-21 Thread Alex Hall
Hi all,
I have an articles model and I have a few questions.

1. Each article can have only one author. However, the admin site
shows a dropdown list of all authors. What I want to happen is for the
"author" field to be auto-filled by the id of the author currently
logged in and creating the article, with no selection possible. How do
I do this? "author" is, by the way, a foreign key into the author
table.

2. Another field of the article table is "media". An article can have
0 or more media files (pictures, zipped folders, mp3s, and so on)
attached to it. I want this to be an upload button. The problem is
that media is stored in its own table, so the admin site will offer a
select list of current media files instead of letting an author upload
a new file. How should this best be handled?

3. Finally, there is a "devices" table. An article must be associated
with one or more devices, for sorting purposes. Currently the devices
show as a multiple select list, but I want them to show as a column of
checkboxes instead. How do I change this in my model?

Thanks in advance!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Design Question

2011-07-21 Thread newtodjango
Sorry about formatting. Also the there is a mistake.

"I'd like to define the Product model..." should be
"I'd like to define the Contract model...

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is there a way to insert data from a csv file into my database?

2011-07-21 Thread lokesh
hi,
you can use python script to upload from csv file to database.
if u r using mysql u can http://sourceforge.net/projects/mysql-python/
download and install this package and use csv reader to read from file
and write it on to tables. Guide(http://www.kitebird.com/articles/
pydbapi.html).
if u r using sqlite3 u can find in (http://docs.python.org/release/
2.5.2/lib/module-sqlite3.html).

-lokesh s


On Jul 21, 12:17 am, Eiram  wrote:
> Greetings,
>
> I'm a newbie in databases, and I was wondering if there is possible to
> insert data from a csv file into one of the tables of my database. I
> heard that you can use a tool called pgloader, but I don't know how to
> use this tool or if it is possible to do this with django. Does anyone
> knows a way to do this on django or pgloader? I really will appreciate
> your help.
>
> Best Regards,
>
> Jary

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: problem with BooleanField form

2011-07-21 Thread ed
You mean like this:

var data = {
url: item.find("#id_url").val(),
title: item.find("#id_title").val(),
tags: item.find("#id_tags").val(),
share: item.find("#id_share").val()
};

Tried it. 'share' is still showing up false...



On Jul 21, 1:29 am, Daniel Roseman  wrote:
> On Thursday, July 21, 2011 4:00:55 AM UTC+1, ed wrote:
>
> > I'm using the following javascript, so I can't check the HTML, can I?
> > How would I go about debugging this?
>
> > function bookmark_save() {
> > var item = $(this).parent();
> > var data = {
> > url: item.find("#id_url").val(),
> > title: item.find("#id_title").val(),
> > tags: item.find("#id_tags").val()
> > };
> > $.post("/save/?ajax", data, function (result) {
> > if (result != "failure") {
> > item.before($("li", result).get(0));
> > item.remove();
> > $("ul.bookmarks .edit").click(bookmark_edit);
> > }
> > else {
> > alert("Failed to validate bookmark before saving.");
> > }
> > });
> > return false;
> > }
>
> > function bookmark_edit() {
> > var item = $(this).parent();
> > var url = item.find(".title").attr("href");
> > item.load(
> > "/save/?ajax&url=" + encodeURIComponent(url),
> > null,
> > function () {
> > $("#save-form").submit(bookmark_save);
> > }
> > );
> > return false;
> > }
>
> > $(document).ready(function () {
> > $("ul.bookmarks .edit").click(bookmark_edit);
> > });
>
> But surely the problem is that you haven't supplied a value for  `share` in
> your Ajax data.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Design Question

2011-07-21 Thread Jani Tiainen
Hi,

So you want to tie Contract with Product(s) with rebate_pct? You then need
custom intermediary m2m table say "ContractProduct" https://docs.djangoproject.com/en/1.3/topics/db/models/#intermediary-manytomany>
for more. So in the end your models would probably look a alike following:

class Contract():
contract_id = models.lIntegerField(...)
products = models.ManyToManyField(Product, through='ContractProduct')

class ContractProduct():
contract = models.ForeignKey(Contract)
product = models.ForeignKey(Product)
rebate_pct = models.DecimalField(max_digits=4, decimal_places=2)

So now you can link Contract with multiple Products adding custom rebate_pct
value to each link.

And what comes to rebate value, I think you want to keep value with product
linkage for two reasons:
1) It's a single scalar value
2) It's probably something that should not be changed ever after saving.

hth,

-- 

Jani Tiainen

On Thu, Jul 21, 2011 at 8:25 PM, newtodjango  wrote:

> Sorry about formatting. Also the there is a mistake.
>
> "I'd like to define the Product model..." should be
> "I'd like to define the Contract model...
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Design Question

2011-07-21 Thread nixlists
On Thu, Jul 21, 2011 at 2:17 PM, Jani Tiainen  wrote:
> Hi,
> So you want to tie Contract with Product(s) with rebate_pct? You then need
> custom intermediary m2m table say "ContractProduct"
> https://docs.djangoproject.com/en/1.3/topics/db/models/#intermediary-manytomany>
> for more. So in the end your models would probably look a alike following:
> class Contract():
>     contract_id = models.lIntegerField(...)
>     products = models.ManyToManyField(Product, through='ContractProduct')
> class ContractProduct():
>     contract = models.ForeignKey(Contract)
>     product = models.ForeignKey(Product)
>     rebate_pct = models.DecimalField(max_digits=4, decimal_places=2)
> So now you can link Contract with multiple Products adding custom rebate_pct
> value to each link.
> And what comes to rebate value, I think you want to keep value with product
> linkage for two reasons:
> 1) It's a single scalar value
> 2) It's probably something that should not be changed ever after saving.
> hth,

Thanks for your response, I think this will work. How would I write a
query to find the rebate_pct per contract per product?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Design Question

2011-07-21 Thread Jani Tiainen
On Thu, Jul 21, 2011 at 10:50 PM, nixlists  wrote:

> On Thu, Jul 21, 2011 at 2:17 PM, Jani Tiainen  wrote:
> > Hi,
> > So you want to tie Contract with Product(s) with rebate_pct? You then
> need
> > custom intermediary m2m table say "ContractProduct"
> >  https://docs.djangoproject.com/en/1.3/topics/db/models/#intermediary-manytomany
> >
> > for more. So in the end your models would probably look a alike
> following:
> > class Contract():
> > contract_id = models.lIntegerField(...)
> > products = models.ManyToManyField(Product, through='ContractProduct')
> > class ContractProduct():
> > contract = models.ForeignKey(Contract)
> > product = models.ForeignKey(Product)
> > rebate_pct = models.DecimalField(max_digits=4, decimal_places=2)
> > So now you can link Contract with multiple Products adding custom
> rebate_pct
> > value to each link.
> > And what comes to rebate value, I think you want to keep value with
> product
> > linkage for two reasons:
> > 1) It's a single scalar value
> > 2) It's probably something that should not be changed ever after saving.
> > hth,
>
> Thanks for your response, I think this will work. How would I write a
> query to find the rebate_pct per contract per product?
>
>
ContractProduct.objects.all()

Following might work also (not sure, but is easy to test in shell for
example):

for c in Contract.objects.all():
for cp in c.contractproduct_set.all():
print c, cp.product, cp.rebate_pct

-- 

Jani Tiainen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Design Question

2011-07-21 Thread nixlists
On Thu, Jul 21, 2011 at 4:30 PM, Jani Tiainen  wrote:
> ContractProduct.objects.all()
> Following might work also (not sure, but is easy to test in shell for
> example):
> for c in Contract.objects.all():
>     for cp in c.contractproduct_set.all():
>         print c, cp.product, cp.rebate_pct
> --
> Jani Tiainen

Thanks. This works but kind of confusing, and I am looking for an easy
way to find rebate_pct given contract and product ids.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Design Question

2011-07-21 Thread Marc Aymerich
On Thu, Jul 21, 2011 at 11:11 PM, nixlists  wrote:

> On Thu, Jul 21, 2011 at 4:30 PM, Jani Tiainen  wrote:
> > ContractProduct.objects.all()
> > Following might work also (not sure, but is easy to test in shell for
> > example):
> > for c in Contract.objects.all():
> > for cp in c.contractproduct_set.all():
> > print c, cp.product, cp.rebate_pct
> > --
> > Jani Tiainen
>
> Thanks. This works but kind of confusing, and I am looking for an easy
> way to find rebate_pct given contract and product ids.
>

Something like this?

ContractProduct.objects.filter(contract__id=X,
product__id=Y).values_list('rebate_pct', flat=True)

or if you already have a contract:
contract.products.filter(product__id=Y).values_list('rebate_pct', flat=True)

or product:
product.contractproduct_set.filter(contract__id=Y).values_list('rebate_pct',
flat=True)


-- 
Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database Design Question

2011-07-21 Thread Marc Aymerich
On Thu, Jul 21, 2011 at 11:33 PM, Marc Aymerich  wrote:

>
>
> On Thu, Jul 21, 2011 at 11:11 PM, nixlists  wrote:
>
>> On Thu, Jul 21, 2011 at 4:30 PM, Jani Tiainen  wrote:
>> > ContractProduct.objects.all()
>> > Following might work also (not sure, but is easy to test in shell for
>> > example):
>> > for c in Contract.objects.all():
>> > for cp in c.contractproduct_set.all():
>> > print c, cp.product, cp.rebate_pct
>> > --
>> > Jani Tiainen
>>
>> Thanks. This works but kind of confusing, and I am looking for an easy
>> way to find rebate_pct given contract and product ids.
>>
>
> Something like this?
>
> ContractProduct.objects.filter(contract__id=X,
> product__id=Y).values_list('rebate_pct', flat=True)
>
> or if you already have a contract:
> contract.products.filter(product__id=Y).values_list('rebate_pct',
> flat=True)
>
> or product:
> product.contractproduct_set.filter(contract__id=Y).values_list('rebate_pct',
> flat=True)
>

ups, I think it should be:
contract.products.filter(id=Y).values_list('rebate_pct', flat=True)
product.contractproduct_set.filter(id=X).values_list('rebate_pct',
flat=True)




-- 
Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Recommendations for load testing/profiling a django site server?

2011-07-21 Thread br
I am running on a Linode 768 VPS and may have some stuff going live
before too long.  I'm wondering what the best way to guage whether I
have enough bandwidth/CPU/memory to handle a significant amount of
traffic is and/or to get an idea of the types of loads the site can
handle before i need to upgrade.

Thanks,
Ben


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Some thoughts on a 'backwards incompatible change' (bug!!) found in latest DDT.. wtf?

2011-07-21 Thread Cal Leeming [Simplicity Media Ltd]
https://github.com/django-debug-toolbar/django-debug-toolbar/issues/186

Does anyone else agree with my comments on that ticket, or have I missed
something? :X

Cal

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Some thoughts on a 'backwards incompatible change' (bug!!) found in latest DDT.. wtf?

2011-07-21 Thread Andre Terra
Totally agreed.

I expect DDT to only be displayed for INTERNAL_IPS and only during DEBUG
mode, it shouldn't be an OR clause.

But why not go ahead and fork it? ;)


Cheers,
AT

On Thu, Jul 21, 2011 at 8:01 PM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> https://github.com/django-debug-toolbar/django-debug-toolbar/issues/186
>
> Does anyone else agree with my comments on that ticket, or have I missed
> something? :X
>
> Cal
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Some thoughts on a 'backwards incompatible change' (bug!!) found in latest DDT.. wtf?

2011-07-21 Thread Cal Leeming [Simplicity Media Ltd]
On Fri, Jul 22, 2011 at 12:22 AM, Andre Terra  wrote:

> Totally agreed.
>
> I expect DDT to only be displayed for INTERNAL_IPS and only during DEBUG
> mode, it shouldn't be an OR clause.
>
> But why not go ahead and fork it? ;)
>

Yeah, someone else just suggested that too. Seems a shame to have to fork
it, for something so simple.

I'm hoping that enough people in here will disagree with his decision, and
that he'll change it back to how it should be, based on a majority vote. (I
doubt this will happen, lol).


>
>
> Cheers,
> AT
>
> On Thu, Jul 21, 2011 at 8:01 PM, Cal Leeming [Simplicity Media Ltd] <
> cal.leem...@simplicitymedialtd.co.uk> wrote:
>
>> https://github.com/django-debug-toolbar/django-debug-toolbar/issues/186
>>
>> Does anyone else agree with my comments on that ticket, or have I missed
>> something? :X
>>
>> Cal
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: https / nginx / uwsgi / django problems with authentification

2011-07-21 Thread Gelonida N
Hi Robert,


Thanks a lot. This is working :-)

I just added
uwsgi_param UWSGI_SCHEME https;


as you suggested.


On 07/21/2011 06:38 AM, Roberto De Ioris wrote:
> 
>> Hi,
>>
>> I'm not sure whether I have to change my django configuration or my
>> nginx cofiguration.
>> (Thus posted to gmane.comp.python.django.user and to
>> gmane.comp.web.nginx.english)
>>
>> I have following setup:
>>
>> - nginx listening on https
>> - most static contents like .css .js images served by nginx
>> - everything else forwarded to django
>>
>> all .html files are in fact templated and should thus be treated by
>> django. Additionally I wanted to grant access to the contents onlyy to
>> authorized users.
>>
>>
>> djangu urls.py setup
>> ---
>>
>> from django.contrib.auth.decorators import login_required
>> from django.views.generic.simple import direct_to_template
>>
>>
>>  url(r'^(?P.*\.html)$',
>>  login_required(direct_to_template),
>>  ),
>>
>>
>> nginx is configured with
>> -
>>
>> location ~ \.*.html$ {
>> uwsgi_pass django;
>> uwsgi_param  QUERY_STRING   $query_string;
>> uwsgi_param  REQUEST_METHOD $request_method;
>> uwsgi_param  CONTENT_TYPE   $content_type;
>> uwsgi_param  CONTENT_LENGTH $content_length;
>>
>> uwsgi_param  REQUEST_URI$request_uri;
>> uwsgi_param  PATH_INFO  $document_uri;
>> uwsgi_param  DOCUMENT_ROOT  $document_root;
>> uwsgi_param  SERVER_PROTOCOL$server_protocol;
>>
>> uwsgi_param  REMOTE_ADDR$remote_addr;
>> uwsgi_param  REMOTE_PORT$remote_port;
>> uwsgi_param  SERVER_PORT$server_port;
>> uwsgi_param  SERVER_NAME$server_name;
>> }
>>
>> uwsgi is called with
>> --
>> uwsgi -s host:port  -H virtual_env_python --pidfile uwsgi.pid \
>> --pp ..-w wsgi_module
>>
>> The problem is, that the first request to
>>
>> https://mysite:myport/index.html
>>
>> is detected as non authenticated access. (that's what I want)
>> and thus django tries to redirect to  redirected to the authentification
>> page (that's also what I want)
>> which should be
>>
>> Django should redirect to
>> https://mysite:myport/accounts/login/?next=/index.html
>>
>> Unfortunately it redirects to
>> http://mysite:myport/accounts/login/?next=/index.html
>>
>>
>> Therefore I get the error message
>> "400 Bad Request The plain HTTP request was sent to HTTPS port"
>>
>> Is there any variable that I can use to tell django, that the protocol
>> is https and not http for the login pages
>>
>> Ideally I would like to have something like an nginx parameter being
>> passed, such that django knows whether the request is coming from an
>> nginx https server ( all redirects should be https:host:port )
>> or from an nginx http server.
>>
>>
>> Does anyone have a similiar setup or has some ideas?
>>
> 
> 
> 
> You can force the protocol using the HTTPS variable (standard, but not
> enabled in nginx) or you can force the protocol to htts using the
> UWSGI_SCHEME variable
> 
> http://projects.unbit.it/uwsgi/wiki/uWSGIVars
> 
> 
> 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread Gelonida N
On 07/18/2011 04:33 PM, bruno desthuilliers wrote:
> On Jul 18, 3:33 pm, Alexander Crössmann
>  wrote:
>> Hi Malcom,
>>
>> I am not sure the management commands are what I want
> 
> Strange enough, it seems that everyone starts by saying this and ends
> up writing custom management commands ;)
> 


I wrote quite some scripts meanwhile, which just set
DJANGO_SETTINGS_MODULE and use then the models.

I think if a django model is only a tiny part of a bigger script, then
management commands are not really advantageous over management commands.

Another issue, that I had is trying to use django under windows with py2exe.

Management commands are no more found, as django would require the
python source code in order to find existing management commands.

Perhaps there is an easy  work around, but I am not aware of one.




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import django models without runing the server

2011-07-21 Thread Kevin Anthony
I found the best way to do this is
python manage.py < script.py
On Jul 21, 2011 8:00 PM, "Gelonida N"  wrote:
> On 07/18/2011 04:33 PM, bruno desthuilliers wrote:
>> On Jul 18, 3:33 pm, Alexander Crössmann
>>  wrote:
>>> Hi Malcom,
>>>
>>> I am not sure the management commands are what I want
>>
>> Strange enough, it seems that everyone starts by saying this and ends
>> up writing custom management commands ;)
>>
>
>
> I wrote quite some scripts meanwhile, which just set
> DJANGO_SETTINGS_MODULE and use then the models.
>
> I think if a django model is only a tiny part of a bigger script, then
> management commands are not really advantageous over management commands.
>
> Another issue, that I had is trying to use django under windows with
py2exe.
>
> Management commands are no more found, as django would require the
> python source code in order to find existing management commands.
>
> Perhaps there is an easy work around, but I am not aware of one.
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django setup environment

2011-07-21 Thread Gelonida N
http://superjared.com/entry/django-and-crontab-best-friends/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Some thoughts on a 'backwards incompatible change' (bug!!) found in latest DDT.. wtf?

2011-07-21 Thread Mike Dewhirst

On 22/07/2011 9:25am, Cal Leeming [Simplicity Media Ltd] wrote:



On Fri, Jul 22, 2011 at 12:22 AM, Andre Terra > wrote:


Totally agreed.

I expect DDT to only be displayed for INTERNAL_IPS and only during
DEBUG mode, it shouldn't be an OR clause.

But why not go ahead and fork it? ;)


Yeah, someone else just suggested that too. Seems a shame to have to 
fork it, for something so simple.


Having seen the discussion on the issue I think there is probably some 
merit on both sides.


Maybe a simple fix is to disable DDT in settings.py - just remove it 
altogether - then add it back in a local_settings.py just for the devs 
who need it?


Mike




I'm hoping that enough people in here will disagree with his decision, 
and that he'll change it back to how it should be, based on a majority 
vote. (I doubt this will happen, lol).




Cheers,
AT

On Thu, Jul 21, 2011 at 8:01 PM, Cal Leeming [Simplicity Media
Ltd] mailto:cal.leem...@simplicitymedialtd.co.uk>> wrote:

https://github.com/django-debug-toolbar/django-debug-toolbar/issues/186


Does anyone else agree with my comments on that ticket, or
have I missed something? :X

Cal
-- 
You received this message because you are subscribed to the

Google Groups "Django users" group.
To post to this group, send email to
django-users@googlegroups.com
.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.


-- 
You received this message because you are subscribed to the Google

Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com
.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google 
Groups "Django users" group.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Setting LOGIN_URL dynamically, for different users, based on app?

2011-07-21 Thread dpapathanasiou
I'd like to be able to support two different types of authenticated
users within a single django project site.

The idea is that Type A users will work in the /dashboard app, and
Type B users will work in the /console app.

Since each app has its own set of models and views, I can do this at
the db level (i.e., /dashboard users have one set of tables, and /
console users have another).

But if I use the built-in django authentication api (https://
docs.djangoproject.com/en/dev/topics/auth/), it seems that I can only
define one value of LOGIN_URL in the project settings.py file.

Is there a way to set LOGIN_URL so that the /dashboard views.py
functions redirect to one location, while the views.py functions for /
console use a different value?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Setting LOGIN_URL dynamically, for different users, based on app?

2011-07-21 Thread Andre Terra
Why not make custom user profiles and write permission checks on your views?

Cheers,
AT

On Thu, Jul 21, 2011 at 10:15 PM, dpapathanasiou <
denis.papathanas...@gmail.com> wrote:

> I'd like to be able to support two different types of authenticated
> users within a single django project site.
>
> The idea is that Type A users will work in the /dashboard app, and
> Type B users will work in the /console app.
>
> Since each app has its own set of models and views, I can do this at
> the db level (i.e., /dashboard users have one set of tables, and /
> console users have another).
>
> But if I use the built-in django authentication api (https://
> docs.djangoproject.com/en/dev/topics/auth/), it seems that I can only
> define one value of LOGIN_URL in the project settings.py file.
>
> Is there a way to set LOGIN_URL so that the /dashboard views.py
> functions redirect to one location, while the views.py functions for /
> console use a different value?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Setting LOGIN_URL dynamically, for different users, based on app?

2011-07-21 Thread dpapathanasiou
How can I do that in the context of the built-in django auth API? Are
there examples or tutorials of that?

On Jul 21, 9:23 pm, Andre Terra  wrote:
> Why not make custom user profiles and write permission checks on your views?
>
> Cheers,
> AT
>
> On Thu, Jul 21, 2011 at 10:15 PM, dpapathanasiou <
>
>
>
> denis.papathanas...@gmail.com> wrote:
> > I'd like to be able to support two different types of authenticated
> > users within a single django project site.
>
> > The idea is that Type A users will work in the /dashboard app, and
> > Type B users will work in the /console app.
>
> > Since each app has its own set of models and views, I can do this at
> > the db level (i.e., /dashboard users have one set of tables, and /
> > console users have another).
>
> > But if I use the built-in django authentication api (https://
> > docs.djangoproject.com/en/dev/topics/auth/), it seems that I can only
> > define one value of LOGIN_URL in the project settings.py file.
>
> > Is there a way to set LOGIN_URL so that the /dashboard views.py
> > functions redirect to one location, while the views.py functions for /
> > console use a different value?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Setting LOGIN_URL dynamically, for different users, based on app?

2011-07-21 Thread Shawn Milochik

On 07/21/2011 10:15 PM, dpapathanasiou wrote:

How can I do that in the context of the built-in django auth API? Are
there examples or tutorials of that?


https://docs.djangoproject.com/en/1.3/topics/auth/#storing-additional-information-about-users

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.