Re: Django cookies

2009-10-25 Thread Rishabh Manocha
On Mon, Oct 26, 2009 at 9:37 AM, Jeffrey Taggarty wrote:

>
> Hello,
>
> I have a web site which shows different content based on a location
> the visitor chooses. e.g: User enters in 55812 as the zip. I know what
> city and area lat/long. that is and give them their content pertinent
> to that area. My question is how can I store this in a cookie so that
> when they return they are not required to always enter their zip code?
>
> I see it as follows:
>
> 1) Set persistent cookie based on their area.
> 2) When they return read cookie, grab zipcode.
> 3) Return content based on the zip code in their cookie.
>
> I can't seem to find any solid information on setting a cookie. Any
> help is greatly appreciated.
>
> Thanks,
>
> Jeff
>
> >
>

Check out
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.set_cookie
.
-- 

Best,

R

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ModelForm - how to post primary key to update existing record?

2009-10-25 Thread robinne

I am noticing that when I load an existing ModelForm into a template,
and I save (POST), I can't seem to get the primary key back in order
to update that specific record. I am starting to head down the path of
formsets...but that is not what I need. I am updating one record only.
Any help is appreciated!

VIEW
def UpdateMember(request):
  if request.method == "POST":
   # I don't seem to have access to primary key...
   # I do have the posted data, and can save to database here.


TEMPLATE (as you can see, I've tried to explicitly include primary
key, both inside and outside the for loop)
 {{ Member.MemberID }}
 {% for field in Member %}
 {{ field.label_tag }}
 {{ field }}
 {% endfor %}

--~--~-~--~~~---~--~~
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: My project is not detecting the geodjango application

2009-10-25 Thread Sahiti Polishetty
Ya.. I am sure that I have added it in INSTALLED_APPS and I rechecked it as
well.. My problem is not yet solved..

On Mon, Oct 26, 2009 at 7:23 AM, Dhruv Adhia  wrote:

> The error means that are you sure you have added "world" in INSTALLED_APPS
> which is in settings.py?
>
> Dhruv Adhia
> http://www.thirdimension.com
>
>
>
>
> On Sun, Oct 25, 2009 at 10:35 AM, Sahiti Polishetty  > wrote:
>
>>  Hello .. I want to have google maps in my application, so i created a
>> project and in that made an application to handle the maps and made the
>> required changes in the settings.py for the above. But i am getting the
>> following error when i am trying to issue the command "python manage.py
>> sqlall world" Error: App with label world could not be found. Are you sure
>> your INSTALLED_APPS setting is correct? Can some one please help in this
>> issue . And my models file is as follows: from django.contrib.gis.db import
>> models class WorldBorders(models.Model): # Regular Django fields
>> corresponding to the attributes in the # world borders shapefile. name =
>> models.CharField(max_length=50) area = models.IntegerField() pop2005 =
>> models.IntegerField('Population 2005') fips = models.CharField('FIPS Code',
>> max_length=2) iso2 = models.CharField('2 Digit ISO', max_length=2) iso3 =
>> models.CharField('3 Digit ISO', max_length=3) un =
>> models.IntegerField('United Nations Code') region =
>> models.IntegerField('Region Code') subregion =
>> models.IntegerField('Sub-Region Code') lon = models.FloatField() lat =
>> models.FloatField() # GeoDjango-specific: a geometry field
>> (MultiPolygonField), and # overriding the default manager with a GeoManager
>> instance. mpoly = models.MultiPolygonField() objects = models.GeoManager() #
>> So the model is pluralized correctly in the admin. class Meta:
>> verbose_name_plural = "World Borders" # Returns the string representation of
>> the model. def __unicode__(self): return self.name
>>
>>
>>
>>
>
> >
>

--~--~-~--~~~---~--~~
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: Behaviour of related objects

2009-10-25 Thread Preston Holmes



On Oct 25, 2:55 pm, Bojan Mihelac  wrote:
> Hi all,
>
> given an many_to_one doctests with Reporter/Article models, the
> following example would fail with "IntegrityError:
> many_to_one_article.reporter_id may not be NULL":
>
> >>> r = Reporter(first_name='John', last_name='Smith', 
> >>> email='j...@example.com')
> >>> a = Article(headline="This is a test", pub_date=datetime(2005, 7, 27), 
> >>> reporter=r)
> >>> r.save()
> >>> a.save()
>
> For me, expected behaviour would be that since article knows it is
> related to reporter it should check reporter's primary key on save.
>
> Am I wrong?

But a is being created before r has an id  - just move the r.save()
line up one.

-Preston

>
> thanks,
> Bojan
--~--~-~--~~~---~--~~
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: Definitive solution for foreignkey filtering in Admin

2009-10-25 Thread Matt Schinckel

On Oct 24, 5:14 am, Tim Valenta  wrote:
> I've been searching for a while on how to intercept querysets in
> forms, to apply a custom filter to the choices on both foreignkey and
> m2m widgets.  I'm surprised at how there are so many similar questions
> out there, dating back to 2006.

[snip]

> The only solution I've seen has dealt with filtering by User foreign
> key (being that User is available in the request object in views), and
> that's primarily for non-Admin views.

[snip]

> I've been looking at the code for the above noted API method,
> formfield_for_foreignkey, and I really can't see a way to get
> references to an instance of the object being edited.  I would need
> such a reference to successfully override that method and filter my
> queryset on this relationship.

I too spent some time looking at formfield_for_foreignkey, and had no
luck.

You can subclass ModelAdmin, and then limit the objects in the field's
queryset.

** admin.py **

class LocationAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
forms.ModelForm.__init__(self, *args, **kwargs)
location = kwargs.get('instance', None)
if location:
self.fields['contract'].queryset = Contract.objects.filter
(company=location.company)

class LocationAdmin(admin.ModelAdmin):
model = Location
form = LocationAdminForm


I also had to do something similar with Inlines, when I did the same
type of thing.  This is not my exact code, but it is very close, and
suited toward your use case.

Matt.
--~--~-~--~~~---~--~~
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 an admin form field is displayed (float to datetime)

2009-10-25 Thread Paul Smith
I've been trying to a modify an admin form so I have a slightly different
user interface compared to the database model.

The main problem is this; in the database model I store a start and end time
as timestamps (a float holding seconds since 1/1/1970). But when the user
wants to edit the times I don't want him to have to deal with big float
values so I've created a new form with DateTimeFields thus;

 

  class MyNewForm(forms.ModelForm):

  start_time = forms.DateTimeField()

  end_time = forms.DateTimeField()

 

  def clean(self):

  cleaned_data = self.cleaned_data

  start = cleaned_data.get('start_time')

  end = cleaned_data.get('end_time')

  cleaned_data['start_time']=time.mktime(start.timetuple())

  if end:

  cleaned_data['end_time']=time.mktime(end.timetuple())

  return cleaned_data

 

  class Meta:

  model = MyModel

 

where MyModel is just;

 

  class MyModel(models.Model):

  start_time = models.FloatField()

  end_time = models.FloatField(null=True)

 

and the admin declaration is;

 

  class MyModelAdmin(admin.ModelAdmin):

  form = MyNewForm

 

Now this cleans any new date/time entries and converts them to floats before
writing to the db just fine, but if the user is editing an existing record I
can't get the existing start and end times to display as, for example,
'2009-10-25 12:00', they always show up as the float values. I've tried to
change this by adding the following __init__ method to MyNewForm;

 

def __init__(self, *args, **kwargs):

super(MyNewForm, self).__init__(*args, **kwargs)

instance=kwargs.get('instance','')

if instance:

self.fields['start_time'] =
forms.DateTimeField(initial=datetime.fromtimestamp(instance.start_time))
# tried this to set the initial value

self.fields['start_time'].initial =
datetime.fromtimestamp(instance.start_time) # then tried this

 

But neither of these seem to override the admin's rendering of the float
times and I'm not sure where that gets decided. I haven't seen any examples
similar to this but would have thought it was fairly common to change the
way data is displayed to the user for editing and then convert it back to
another form (via clean) when a change is submitted.

 

Paul


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



slow tests on 1.1.1 w/ sqlite

2009-10-25 Thread Phlip

Djangos:

This is the "slow test" question, again. I have time tested with 1.0.3
and 1.1.1, and a batch of only like 20 tests takes a minute on both
versions. Yes to sqlite3, in :memory:. The nature of the question is
I'm an old-skool Pythonist but I wouldn't know where to start
diagnosing this issue.

Under 1.1.1, when I add this print...

class SQLiteCursorWrapper(Database.Cursor):

def execute(self, query, params=()):
query = self.convert_query(query, len(params))
print query
return Database.Cursor.execute(self, query, params)

...I see quadrillions of INSERT statements, and never any BEGIN
TRANSACTION statements.

The base settings.py contains DATABASE_SUPPORTS_TRANSACTIONS = True

I'm aware that :memory: is fast, and sqlite3 is faster than other
situations. But 1 minute for 20 tests is horrific (and reminds me of
you-know-who), so I'm open to any suggestions how to profile the
system. The code is INSERTing once per test case, not transacting.

If the basic Django apps were extruded by 1.0.x, do they need an
upgrade?

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



generic views 404 error

2009-10-25 Thread Ross

I just neared the end of the poll application and converted everything
to generic views according to the tutorial. Once I started up the
server though, I could only find my admin page. I tried using the
newly named urls but I keep getting Page not Found 404 errors. Same
thing happens when I type in the old urls. What did I do wrong? I've
combed my syntax and can't find anything different from what the
tutorial instructed.
--~--~-~--~~~---~--~~
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: My project is not detecting the geodjango application

2009-10-25 Thread Dhruv Adhia
The error means that are you sure you have added "world" in INSTALLED_APPS
which is in settings.py?

Dhruv Adhia
http://www.thirdimension.com



On Sun, Oct 25, 2009 at 10:35 AM, Sahiti Polishetty
wrote:

>  Hello .. I want to have google maps in my application, so i created a
> project and in that made an application to handle the maps and made the
> required changes in the settings.py for the above. But i am getting the
> following error when i am trying to issue the command "python manage.py
> sqlall world" Error: App with label world could not be found. Are you sure
> your INSTALLED_APPS setting is correct? Can some one please help in this
> issue . And my models file is as follows: from django.contrib.gis.db import
> models class WorldBorders(models.Model): # Regular Django fields
> corresponding to the attributes in the # world borders shapefile. name =
> models.CharField(max_length=50) area = models.IntegerField() pop2005 =
> models.IntegerField('Population 2005') fips = models.CharField('FIPS Code',
> max_length=2) iso2 = models.CharField('2 Digit ISO', max_length=2) iso3 =
> models.CharField('3 Digit ISO', max_length=3) un =
> models.IntegerField('United Nations Code') region =
> models.IntegerField('Region Code') subregion =
> models.IntegerField('Sub-Region Code') lon = models.FloatField() lat =
> models.FloatField() # GeoDjango-specific: a geometry field
> (MultiPolygonField), and # overriding the default manager with a GeoManager
> instance. mpoly = models.MultiPolygonField() objects = models.GeoManager() #
> So the model is pluralized correctly in the admin. class Meta:
> verbose_name_plural = "World Borders" # Returns the string representation of
> the model. def __unicode__(self): return self.name
>
>
> >
>

--~--~-~--~~~---~--~~
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 cookies

2009-10-25 Thread Jeffrey Taggarty

Hello,

I have a web site which shows different content based on a location
the visitor chooses. e.g: User enters in 55812 as the zip. I know what
city and area lat/long. that is and give them their content pertinent
to that area. My question is how can I store this in a cookie so that
when they return they are not required to always enter their zip code?

I see it as follows:

1) Set persistent cookie based on their area.
2) When they return read cookie, grab zipcode.
3) Return content based on the zip code in their cookie.

I can't seem to find any solid information on setting a cookie. Any
help is greatly appreciated.

Thanks,

Jeff

--~--~-~--~~~---~--~~
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: Passing Parameter to form in inlineformset_factory

2009-10-25 Thread Andew Gee

Thanks for the help.

I did find this as a solution ad it seems to work

Formset = inlineformset_factory(ModelA, ModelB form=MyForm)
Formset.form = staticmethod(curry(MyForm, reaOnly=readOnlyvalue))
myFormset = Formset(request.Files, instance=modelAInst)

Regards
Andrew

Andew Gee wrote:
> Hi,
>
>
> I have the following Form defined
>
> class MyForm(ModelForm)
>
>   def __init__(self, readOnly=False, *args, **kwargs):
>   if readOnly:
>  Do stuff to make the inputs readonly
>
> MyForm works perfectly when I instantiate it in the view as a form
> form = MyForm(readOnly=True, instance=ModelA)
>
> but when I try to use it in the inlineformset_factory I get the error
>
> NoneType object is not callable.
>
> I know the problem id the way I am using the MyForm in the inline call
> because I get the same error if I do either of the following
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm
> (readOnly=True))
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm())
>
> but it works if I do
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm)
>
> obviously the readOnly param defaults to False and my inputs are not
> changed.
>
> Does anyone know how I can pass the readOnly param to MyForm using the
> inlineformset_factory or how else I can achieve what I want?
>
> Thanks
> Andrew
--~--~-~--~~~---~--~~
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: Interesting code abstraction Challenge

2009-10-25 Thread Jason Beaudoin

Thanks for the thoughts Preston!


> I think a base class with subclasses is the best approach.
>
> Define as much common behavior as possible, set up defaults for those
> fields needed by your outbound API

Indeed, thanks for the confirmation. I think it's time for experimentation!


> How are you handling the branching lookup of what subclass to use?
> You might name the subclasses in some way that they can be derived
> from the partner URL - or some other way that intelligently selects
> the subclass for you

Incoming requests for processing would have associations with specific
backend partners defined in the database and processed as part of the
request, so the branching will be tied into this.


> I assume you've looked at django-piston

I had not seen it, so thank you for pointing me in this direction!


~Jason

--~--~-~--~~~---~--~~
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-registration] urls in templates

2009-10-25 Thread Ethan Jucovy

Look in django-registration's registration/urls.py to find the names.
IIRC it's like "auth_login" and "registration_register" (both with no
parameters).

egj

On Sun, Oct 25, 2009 at 8:09 PM, Sławek Tuleja  wrote:
>
> Hi
> I am using django-registration. In my base.html file I have:
> login
> register
>
> How to avoid hardcoded urls?
> {% url ?:? %}
>
> greetings
> >
>

--~--~-~--~~~---~--~~
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-registration] urls in templates

2009-10-25 Thread Sławek Tuleja

Hi
I am using django-registration. In my base.html file I have:
login
register

How to avoid hardcoded urls?
{% url ?:? %}

greetings
--~--~-~--~~~---~--~~
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: Model design

2009-10-25 Thread Caisys

Thanks but I am not very familiar with forms yet I barely managed to
override the default form.
However, I thought that its ok for the time being since places and
subplaces are not changed frequently so i can live with it for the
time being and move to more important parts until I am more familiar
with the forms.

I just need to know how to call the a related field in __unicode__
(self)

On Oct 25, 2:30 pm, "Vinicius Mendes | meiocodigo.com"
 wrote:
> On Oct 25, 4:53 am, Caisys  wrote:
>
> > > Just override the form in the inlne admin. All you have to do is set a
> > > default in the field you want.
>
> > I managed to do that but now all the extra fields have the default
> > text not just one.
>
> What about overriding the formset? You override the __init__ of the
> formset and before calling super, you add an initial data to the
> formset adding the default value for the first form.
>
> > > In this case i prefer the approach of creating a "fake" field called
> > > places, populated with the places, and when the user select the place,
> > > you do an ajax request and populate the subplace select with the
> > > subplaces from the selected place. You will have to override the form
> > > in the ModelAdmin and add this behaviour to the form. Also you will
> > > have to create a view to retrieve the subplaces based in the selected
> > > place.
>
> > I am not so sure how to do that yet. However, i would like to know how
> > i could not return the related object name in __unicode__ . Where did
> > I go wrong?
>
> > Thanks
>
> > On Oct 24, 1:38 pm, "Vinicius Mendes | meiocodigo.com"
>
> >  wrote:
> > > On Oct 24, 7:14 am, Caisys  wrote:
>
> > > > Thanks !!! I also felt the second sounds more "right" which leads to
> > > > two requirements, the first is for convenience but the second is a
> > > > must:
>
> > > > 1) On the admin page for add Place I will put 2 or 3 slots for adding
> > > > Subplace to a place ... is there a way where the first one would be
> > > > filled with "default" by default? so that each created place would
> > > > have a default subplace?
>
> > > Just override the form in the inlne admin. All you have to do is set a
> > > default in the field you want.
>
> > > > 2) On the admin page for add event there will be a drop down list for
> > > > the subplace most of the subplaces will be called "default" is
> > > > there a way to change the label on drop down list to "place -
> > > > subplace". i tried to change the __unicode__ of subplace to "return
> > > > u"% - %" % (self.place, self.name)" but it generated and error that
> > > > subplace object has no attribute 'place'.
>
> > > In this case i prefer the approach of creating a "fake" field called
> > > places, populated with the places, and when the user select the place,
> > > you do an ajax request and populate the subplace select with the
> > > subplaces from the selected place. You will have to override the form
> > > in the ModelAdmin and add this behaviour to the form. Also you will
> > > have to create a view to retrieve the subplaces based in the selected
> > > place.
>
> > > > thanks
>
> > > > On Oct 24, 2:27 am, Léon Dignòn  wrote:
>
> > > > > The second sounds more logically.
>
> > > > > On 23 Okt., 15:41, chefsmart  wrote:
>
> > > > > > I would go with your second solution.
>
> > > > > > On Oct 23, 5:17 pm, Caisys  wrote:
>
> > > > > > > Hi,
> > > > > > > I have classes for Event, Place and Subplace. Some of the Places 
> > > > > > > are
> > > > > > > divided into different Halls (Subplace) and some have only one. I
> > > > > > > would like to know how design the relations between the classes.
>
> > > > > > > 1) Should I put two columns in the Event one FK to Place and 
> > > > > > > another
> > > > > > > FK to Hall?
> > > > > > > 2) Should I create one FK only to Hall and create a record in 
> > > > > > > Hall for
> > > > > > > every Place even if the Place has no Halls?
>
> > > > > > > Thanks- Zitierten Text ausblenden -
>
> > > > > > - Zitierten Text anzeigen -

--~--~-~--~~~---~--~~
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: update() (for bulks) is a atomic operation?

2009-10-25 Thread Mikhail Korobov

Yes, it's a single query.

Take a look at django-debug-toolbar. It can display all SQL queries
that was executed during request/response so you'll always be sure
what's going on.

On 26 окт, 03:12, wancharle sebastiao quirino 
wrote:
> Hello,
>
> I currently am using raw sql to make an atomic operation of the following :
>
> UPDATE table SET field1 = 0, flag = 'A' WHERE flag = 'I'
>
> Reading the documentation I realized I could do this:
>
> Table.objects.filter(flag='I').update(field1=0,flag='A')
>
> I want to make sure that this is a unique operation. (to avoid problems of
> parallelism and concurrency)
>
> Someone could confirm me this? Apparently the limitations imposed by the
> documentation already gives a hint that is a single query but I want to be
> sure.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



update() (for bulks) is a atomic operation?

2009-10-25 Thread wancharle sebastiao quirino
Hello,

I currently am using raw sql to make an atomic operation of the following :

UPDATE table SET field1 = 0, flag = 'A' WHERE flag = 'I'

Reading the documentation I realized I could do this:

Table.objects.filter(flag='I').update(field1=0,flag='A')

I want to make sure that this is a unique operation. (to avoid problems of
parallelism and concurrency)

Someone could confirm me this? Apparently the limitations imposed by the
documentation already gives a hint that is a single query but I want to be
sure.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ManyToMany Manager

2009-10-25 Thread Steven Stelmach

Hi all,

I'm working with a content model (say, for simplicity, that we have
articles and images) that has a published status of either "Published"
or "Draft". In the admin interface, I have a widget to associate
images with articles as related content (a manytomany field).

On my site, I currently have a default manager for content that
filters out these draft items, so in the admin, it is not possible for
the field to show or select these draft items in the related content
lookup field. Is there any possible way to either prepopulate the
manytomany field in admin with the correct value or to make the
default manytomany manager for admin different than the default for
the rest of the site?

Thanks,
Steven
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Behaviour of related objects

2009-10-25 Thread Bojan Mihelac

Hi all,

given an many_to_one doctests with Reporter/Article models, the
following example would fail with "IntegrityError:
many_to_one_article.reporter_id may not be NULL":

>>> r = Reporter(first_name='John', last_name='Smith', email='j...@example.com')
>>> a = Article(headline="This is a test", pub_date=datetime(2005, 7, 27), 
>>> reporter=r)
>>> r.save()
>>> a.save()

For me, expected behaviour would be that since article knows it is
related to reporter it should check reporter's primary key on save.

Am I wrong?

thanks,
Bojan
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ANN - Satchmo 0.9 Released

2009-10-25 Thread Chris Moffitt
I am very happy to announce that Satchmo 0.9 is now released.

Satchmo is an ecommerce framework built on the Django framework. It is
designed to be robust and full featured out of the box but allow developers
flexibility to modify the store to fit your unique needs.

This release is a major milestone in our path towards 1.0. This release has
been in active development for over a year and includes many enhancements,
new features and bug fixes. You can read the full changelog here -
http://www.satchmoproject.com/docs/svn/release-notes-0-9.html

Some of the highlights:
- Major reorganization of the Satchmo components to make it more modular
- New US SST tax module
- New Canada post shipping module
- Google checkout v2 integration
- Migrated to using Sorl Thumbnails
- Upgraded Authorize.net to ssl v3.0
- Improved currency display in the admin
- Many bug fixes and performance improvements

>From a project perspective, this is the first release since our migration to
bitbucket for code hosting and distributed development support. We have also
made multiple updates and improvements to the documentation system to make
it more complete and easier to navigate. All of these changes have been
instrumental in getting Satchmo on a solid foundation for this release.

For more info:
You can download Satchmo here -
http://bitbucket.org/chris1610/satchmo/downloads/
The full documentation is here - http://www.satchmoproject.com/docs/svn/
Which includes this quickstart tutorial -
http://www.satchmoproject.com/docs/svn/quickstart.html

Thank you to everyone that has contributed to Satchmo and I look forward to
finalizing a 1.0 release.

-Chris

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How to import doctests?

2009-10-25 Thread toinbis

Hi everyone,

i'm strugling to make $python manage.py test run my doctest.
My folder/file strukture is as follows

myproject/myapp/tests.py
 /my_tests/__init__.py
/my_tests/unittst.py
   /my_tests/doctst.py

I am successfully importing/running unittests to test.py, but can't
make any doctest to make work:(


My file contents are as follows:

===
tmyapp/test.py contains
===
<...>
from my_tests import doctst
import my_tests
<...>

===
/myapp/my_tests/__init__.py

import doctst

__test__ = {
'My_test': doctst,
}

===
myapp/my_tests/doctst.py
===
__doc__ = """
>>> print "django"
djangoo
"""

Thanks in advance for any help!

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



My project is not detecting the geodjango application

2009-10-25 Thread Sahiti Polishetty
Hello .. I want to have google maps in my application, so i created a
project and in that made an application to handle the maps and made the
required changes in the settings.py for the above. But i am getting the
following error when i am trying to issue the command "python manage.py
sqlall world" Error: App with label world could not be found. Are you sure
your INSTALLED_APPS setting is correct? Can some one please help in this
issue . And my models file is as follows: from django.contrib.gis.db import
models class WorldBorders(models.Model): # Regular Django fields
corresponding to the attributes in the # world borders shapefile. name =
models.CharField(max_length=50) area = models.IntegerField() pop2005 =
models.IntegerField('Population 2005') fips = models.CharField('FIPS Code',
max_length=2) iso2 = models.CharField('2 Digit ISO', max_length=2) iso3 =
models.CharField('3 Digit ISO', max_length=3) un =
models.IntegerField('United Nations Code') region =
models.IntegerField('Region Code') subregion =
models.IntegerField('Sub-Region Code') lon = models.FloatField() lat =
models.FloatField() # GeoDjango-specific: a geometry field
(MultiPolygonField), and # overriding the default manager with a GeoManager
instance. mpoly = models.MultiPolygonField() objects = models.GeoManager() #
So the model is pluralized correctly in the admin. class Meta:
verbose_name_plural = "World Borders" # Returns the string representation of
the model. def __unicode__(self): return self.name

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How to filter admin site so that you can select multiple values of a filter?

2009-10-25 Thread DiCoS

Hello. Since the application works only through the admin area of
Realtors. I have a table and apartments linked to this table with a
table areas. I have to organize the search for apartments in several
areas. In order not to injure the hand of Realtors, a set of regions,
separated by commas, decided to make a filter list, which you can
select multiple values. Nuzhny snippet I found, but I think that
someone with a similar problem is encountered.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Defining a "list" field consisting of custom models

2009-10-25 Thread weblogger

Hi,

With my project I'd like to create an industry-aimed application that
offers the users to gain a quick and easy overview over different
jobs. Therefore I've thought of three database models:

1) The basic Material model. This model consists of simple fields like
the name of the material, its size and weight, its purchase price, its
stock location etc.

2) The Set model. This model consists of multiple materials and some
other simple fields similar to those in 1).

3) The Job overview model. This model consists of multiple sets and
some job-related attributes.

The basic material model of course is easy to design, but I got stuck
at the following problem:
How do I define a model field for the set model that lets the user
insert the material models like e.g. on a shopping list ("I want 20
units of this, 5 units of that etc.")? My best approach so far would
be a ManyToManyField(Material) but this field only lets me define
which types of materials I'd like to include in a set, not how many of
these materials. Also, as far as I understood, the ManyToManyField
links materials and sets bi-directional whereas I'd like only a
unidirectional link from set model to material model.

I'm sure there's an elegant and sophisticated way to solve this issue
(like in many Django uses I've experienced so far), but as I'm quite
new to both Django and Python I require a bit of your friendly help,
please. ;-)

I hope I described my problem properly, if there's something not fully
clear, just ask.

Best regards and thanks in advance!

--~--~-~--~~~---~--~~
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: Model design

2009-10-25 Thread Vinicius Mendes | meiocodigo.com

On Oct 25, 4:53 am, Caisys  wrote:
> > Just override the form in the inlne admin. All you have to do is set a
> > default in the field you want.
>
> I managed to do that but now all the extra fields have the default
> text not just one.
>

What about overriding the formset? You override the __init__ of the
formset and before calling super, you add an initial data to the
formset adding the default value for the first form.

> > In this case i prefer the approach of creating a "fake" field called
> > places, populated with the places, and when the user select the place,
> > you do an ajax request and populate the subplace select with the
> > subplaces from the selected place. You will have to override the form
> > in the ModelAdmin and add this behaviour to the form. Also you will
> > have to create a view to retrieve the subplaces based in the selected
> > place.
>
> I am not so sure how to do that yet. However, i would like to know how
> i could not return the related object name in __unicode__ . Where did
> I go wrong?
>
> Thanks
>
> On Oct 24, 1:38 pm, "Vinicius Mendes | meiocodigo.com"
>
>  wrote:
> > On Oct 24, 7:14 am, Caisys  wrote:
>
> > > Thanks !!! I also felt the second sounds more "right" which leads to
> > > two requirements, the first is for convenience but the second is a
> > > must:
>
> > > 1) On the admin page for add Place I will put 2 or 3 slots for adding
> > > Subplace to a place ... is there a way where the first one would be
> > > filled with "default" by default? so that each created place would
> > > have a default subplace?
>
> > Just override the form in the inlne admin. All you have to do is set a
> > default in the field you want.
>
> > > 2) On the admin page for add event there will be a drop down list for
> > > the subplace most of the subplaces will be called "default" is
> > > there a way to change the label on drop down list to "place -
> > > subplace". i tried to change the __unicode__ of subplace to "return
> > > u"% - %" % (self.place, self.name)" but it generated and error that
> > > subplace object has no attribute 'place'.
>
> > In this case i prefer the approach of creating a "fake" field called
> > places, populated with the places, and when the user select the place,
> > you do an ajax request and populate the subplace select with the
> > subplaces from the selected place. You will have to override the form
> > in the ModelAdmin and add this behaviour to the form. Also you will
> > have to create a view to retrieve the subplaces based in the selected
> > place.
>
> > > thanks
>
> > > On Oct 24, 2:27 am, Léon Dignòn  wrote:
>
> > > > The second sounds more logically.
>
> > > > On 23 Okt., 15:41, chefsmart  wrote:
>
> > > > > I would go with your second solution.
>
> > > > > On Oct 23, 5:17 pm, Caisys  wrote:
>
> > > > > > Hi,
> > > > > > I have classes for Event, Place and Subplace. Some of the Places are
> > > > > > divided into different Halls (Subplace) and some have only one. I
> > > > > > would like to know how design the relations between the classes.
>
> > > > > > 1) Should I put two columns in the Event one FK to Place and another
> > > > > > FK to Hall?
> > > > > > 2) Should I create one FK only to Hall and create a record in Hall 
> > > > > > for
> > > > > > every Place even if the Place has no Halls?
>
> > > > > > Thanks- Zitierten Text ausblenden -
>
> > > > > - Zitierten Text anzeigen -
--~--~-~--~~~---~--~~
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: Do reverse relations eventually kill performance?

2009-10-25 Thread Gerard

Hiya Tim,

Thanx for the response. Thing is I already have queries running like this:

Customer.objects.filter(user=request.user).order_by('company_name')

The problem however is that I dont trust myself enough to never make a 
msitake to show the wrong data to the wrong user. All my models have a 
"owner" field, but if the queries are not using that there's unwanted data 
disclosure.

I'm trying to figure out if it's possible to write a tiny piece of 
middleware that alarms me when a query is invoked without filtering on the 
owner field.

And at least have it running during development. Would that be afeasible option?

Thanx,

Regards,

Gerard.


Tim Chase wrote:
> Gerard wrote:
>> Hi all,
>>
>> I'm working on a safe way to get users to only see there own records. I've 
>> been working on subclassing model.Manager and requiring a 'owner' parm for 
>> filter() or otherwise returning an emtpy query set .. just to failsafe my 
>> own view coding.
>>
>> Then I figured I could get records in my view via the user.whatever_objects 
>> like this:
>>
>>  user = User.objects.get(username=request.user)
>>  customer_list = user.customers.all().order_by('company_name')
>>
>> But that would make two db connects. When growing in scale, could this 
>> eventually be a performance bottleneck?
> 
> This might be rewritable as
> 
> Customer.objects.filter(user=request.user).order_by('company_name')
> 
> or
> 
> request.user.customers.all().order_by('company_name')
> 
> Test each to see how many queries (not connections) are sent in 
> each case.
> 
> -tim
> 
> 
> 
> > 


-- 
self.url = www.gerardjp.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
-~--~~~~--~~--~--~---



Re: Do reverse relations eventually kill performance?

2009-10-25 Thread Tim Chase

Gerard wrote:
> Hi all,
> 
> I'm working on a safe way to get users to only see there own records. I've 
> been working on subclassing model.Manager and requiring a 'owner' parm for 
> filter() or otherwise returning an emtpy query set .. just to failsafe my 
> own view coding.
> 
> Then I figured I could get records in my view via the user.whatever_objects 
> like this:
> 
>  user = User.objects.get(username=request.user)
>  customer_list = user.customers.all().order_by('company_name')
> 
> But that would make two db connects. When growing in scale, could this 
> eventually be a performance bottleneck?

This might be rewritable as

Customer.objects.filter(user=request.user).order_by('company_name')

or

request.user.customers.all().order_by('company_name')

Test each to see how many queries (not connections) are sent in 
each case.

-tim



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Do reverse relations eventually kill performance?

2009-10-25 Thread Gerard

Hi all,

I'm working on a safe way to get users to only see there own records. I've 
been working on subclassing model.Manager and requiring a 'owner' parm for 
filter() or otherwise returning an emtpy query set .. just to failsafe my 
own view coding.

Then I figured I could get records in my view via the user.whatever_objects 
like this:

 user = User.objects.get(username=request.user)
 customer_list = user.customers.all().order_by('company_name')

But that would make two db connects. When growing in scale, could this 
eventually be a performance bottleneck?

I ask this because now I can still choose how to set things up without 
refactoring my codebase.

Thanx a lot.

Regards,

Gerard.

-- 
self.url = www.gerardjp.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
-~--~~~~--~~--~--~---



Re: Model design

2009-10-25 Thread Caisys

> Just override the form in the inlne admin. All you have to do is set a
> default in the field you want.

I managed to do that but now all the extra fields have the default
text not just one.

> In this case i prefer the approach of creating a "fake" field called
> places, populated with the places, and when the user select the place,
> you do an ajax request and populate the subplace select with the
> subplaces from the selected place. You will have to override the form
> in the ModelAdmin and add this behaviour to the form. Also you will
> have to create a view to retrieve the subplaces based in the selected
> place.


I am not so sure how to do that yet. However, i would like to know how
i could not return the related object name in __unicode__ . Where did
I go wrong?

Thanks



On Oct 24, 1:38 pm, "Vinicius Mendes | meiocodigo.com"
 wrote:
> On Oct 24, 7:14 am, Caisys  wrote:
>
> > Thanks !!! I also felt the second sounds more "right" which leads to
> > two requirements, the first is for convenience but the second is a
> > must:
>
> > 1) On the admin page for add Place I will put 2 or 3 slots for adding
> > Subplace to a place ... is there a way where the first one would be
> > filled with "default" by default? so that each created place would
> > have a default subplace?
>
> Just override the form in the inlne admin. All you have to do is set a
> default in the field you want.
>
> > 2) On the admin page for add event there will be a drop down list for
> > the subplace most of the subplaces will be called "default" is
> > there a way to change the label on drop down list to "place -
> > subplace". i tried to change the __unicode__ of subplace to "return
> > u"% - %" % (self.place, self.name)" but it generated and error that
> > subplace object has no attribute 'place'.
>
> In this case i prefer the approach of creating a "fake" field called
> places, populated with the places, and when the user select the place,
> you do an ajax request and populate the subplace select with the
> subplaces from the selected place. You will have to override the form
> in the ModelAdmin and add this behaviour to the form. Also you will
> have to create a view to retrieve the subplaces based in the selected
> place.
>
> > thanks
>
> > On Oct 24, 2:27 am, Léon Dignòn  wrote:
>
> > > The second sounds more logically.
>
> > > On 23 Okt., 15:41, chefsmart  wrote:
>
> > > > I would go with your second solution.
>
> > > > On Oct 23, 5:17 pm, Caisys  wrote:
>
> > > > > Hi,
> > > > > I have classes for Event, Place and Subplace. Some of the Places are
> > > > > divided into different Halls (Subplace) and some have only one. I
> > > > > would like to know how design the relations between the classes.
>
> > > > > 1) Should I put two columns in the Event one FK to Place and another
> > > > > FK to Hall?
> > > > > 2) Should I create one FK only to Hall and create a record in Hall for
> > > > > every Place even if the Place has no Halls?
>
> > > > > Thanks- Zitierten Text ausblenden -
>
> > > > - Zitierten Text anzeigen -
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---