Admin, m2m relationship and custom save method: is save_related of any help?

2012-11-02 Thread Fabio Natali

Hi!

Snippet: http://dpaste.com/822354/

Idea: a product is made up of different components, each component 
having a certain cost. I want a model for product and component. Given a 
product I need to know its total cost.


Example: a car is made up of 4 wheels, 1 body and 1 engine. Given that 
it's 100$ for a wheel, 1000$ for a body and 500$ for an engine, car 
total cost sums up to 1900$.


In my snippet I use a m2m relationship through a ComponentQty model so 
that I can tell how many components of the same type are needed, eg: 4 
wheels for product car, 2 wheels for product motorbike.


In the admin I make use of a tabular inline to possibly create Product 
and Component objects at the same time.


Then I defined a custom save method so that product total cost is 
calculated and saved.


However, if I create a new product and some new components in the admin, 
my custom save method will go pear shaped. That's because components 
have not yet been created when product is saved. If I save my same 
product a second time, then the save method will calculate total cost 
correctly.


It looks like this is a known issue (or behaviour). I have heard Django 
1.4 save_related should address this but I can't find no real example of 
its use.


Could you help me and tell something more (possibly a real example) 
about save_related? Do you think that could solve my problem?


Cheers, Fabio.

PS: would you please CC to my email address? fa...@fnstudio.it

--
Fabio Natali

--
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: no Polls in the admin page

2012-11-02 Thread Elena Williams
Actually the minimum requirement for the application to appear in admin is
this (here in docs:
https://docs.djangoproject.com/en/dev/intro/tutorial02/#make-the-poll-app-modifiable-in-the-admin):


admin.py:

from django.contrib import admin
from mysite.polls.models import Poll, Choice

# `register()` optionally takes a second argument of a `admin.ModelAdmin`
object
admin.site.register(Poll)
admin.site.register(Choice)


Though as Sandeep put in this code --  in this case you probably would like
the `polls.Choice` inline, which would look like this:

admin.py:

from django.contrib import admin
from mysite.polls.models import Poll, Choice

class ChoiceInline(admin.TabularInline):
model = Choice
extra = 1

class PollAdmin(admin.ModelAdmin):
inlines = [ChoiceInline]

admin.site.register(Poll, PollAdmin)



---
Elena :)
@elequ
04022 90172



On Fri, Nov 2, 2012 at 2:42 PM, Sandeep kaur  wrote:

> On Fri, Nov 2, 2012 at 12:29 AM, Mihail Mihalache
>  wrote:
> > I have followed the django tutorial up to part 2 -
> > https://docs.djangoproject.com/en/1.4/intro/tutorial02/ .
> > Everything worked fine, until I couldn't see the Polls entry on the admin
> > page. I have checked that I have done everything mentioned in the
> tutorial.
> > I get no error whatsoever. I have no idea what's wrong.
> > There is a polls entry INSTALLED_APPS.
> >
> Your admin.py file should have this code :
> -
> from mysite.polls.models import Poll
> from django.contrib import admin
> from mysite.polls.models import Choice
>
>
> class ChoiceInline(admin.TabularInline):
> model = Choice
> extra = 3
>
> class PollAdmin(admin.ModelAdmin):
> fieldsets = [
> (None,   {'fields': ['question']}),
> ('Date information', {'fields': ['pub_date']}),
> ]
> inlines = [ChoiceInline]
> list_display = ('question', 'pub_date')
> list_filter = ['pub_date']
> search_fields = ['question']
>
> admin.site.register(Poll, PollAdmin)
>
> -
>
> --
> Sandeep Kaur
> E-Mail: mkaurkha...@gmail.com
> Blog: sandymadaan.wordpress.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.
>
>

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



Help with Custom model field and Custom validation for EmailField().

2012-11-02 Thread Dilip M
Hi,

I am new to Django. Went through docs before posting this.. I have a model 
and form like this.

models.py:

class Recipients(models.Model):
 dev = models.EmailField()
 qa = models.EmailField()
 cc = models.MultipleEmailField()

forms.py:

class RecipientsForm(forms.ModelForm):

class Meta:
model = Recipients


Now I want to,

1. Add *additional* validation for models.EmailField(). Something like 
check if email id entered exists in LDAP db.
2. Create new model custom field MultipleEmailField(), which would split 
emails separated by comma and uses modified validation of 
models.EmailField() done in step 1.

I am going through docs, but not able to figure out how to put things 
together! Here is what I understood.

MultipleEmailField() should go in /fields.py. But how to make 
it to run default validation of models.EmailField() and than do custom 
validation?


Any help appreciated..


Thanks. Dilip

-- 
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/-/aIny3y7HPS4J.
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 1.5, subclass AbstractUser -> NameError: name 'settings' is not defined

2012-11-02 Thread Michael Muster
Hi,

I am using django 1.5 and want to add an extra
field to the django user class.
The documentation says that i have to subclass AbstractUser
and add extra fields to it.

So i tried it, in my app 'news' i have:

from django.contrib.auth.models import AbstractUser

class cpUser(AbstractUser):
twitter = models.CharField(max_length=100)
def __unicode__(self):
return self.twitter


and in my settings.py file:

AUTH_USER_MODEL = 'news.cpUser'

however, after running 

$ python manage syncdb 

i get

NameError: name 'settings' is not defined

What am i doing wrong?



best regards,
Michael

-- 
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: planetdjango.org down?

2012-11-02 Thread Adomas Paltanavičius
On Friday, October 26, 2012 3:35:45 PM UTC+1, Alexandre Provencio wrote:
>
> Can't access since yesterday :/ 
>

I am looking into this. Should be back over the weekend.

Thanks!
Adomas

-- 
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/-/1ANIKIBGcyAJ.
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 1.5, subclass AbstractUser -> NameError: name 'settings' is not defined

2012-11-02 Thread Russell Keith-Magee
On Fri, Nov 2, 2012 at 4:34 PM, Michael Muster <
michael.mus...@googlemail.com> wrote:

> Hi,
>
> I am using django 1.5 and want to add an extra
> field to the django user class.
> The documentation says that i have to subclass AbstractUser
> and add extra fields to it.
>
> So i tried it, in my app 'news' i have:
>
> from django.contrib.auth.models import AbstractUser
>
> class cpUser(AbstractUser):
> twitter = models.CharField(max_length=100)
> def __unicode__(self):
> return self.twitter
>
>
> and in my settings.py file:
>
> AUTH_USER_MODEL = 'news.cpUser'
>
> however, after running
>
> $ python manage syncdb
>
> i get
>
> NameError: name 'settings' is not defined
>
> What am i doing wrong?
>
>
>
> best regards,
> Michael
>
> --
> 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: django 1.5, subclass AbstractUser -> NameError: name 'settings' is not defined

2012-11-02 Thread Russell Keith-Magee
(Apologies for the first reply -- my send button misfired…)

Hi Michael,

It sounds like something else - not related to the your User model - is
going wrong with your app; the error about settings doesn't sound like
something the auth system would be generating.

Can you run:

./manage syncdb --traceback

so we can get the full context of the error message?

Yours,
Russ Magee %-)

On Fri, Nov 2, 2012 at 4:34 PM, Michael Muster <
michael.mus...@googlemail.com> wrote:

> Hi,
>
> I am using django 1.5 and want to add an extra
> field to the django user class.
> The documentation says that i have to subclass AbstractUser
> and add extra fields to it.
>
> So i tried it, in my app 'news' i have:
>
> from django.contrib.auth.models import AbstractUser
>
> class cpUser(AbstractUser):
> twitter = models.CharField(max_length=100)
> def __unicode__(self):
> return self.twitter
>
>
> and in my settings.py file:
>
> AUTH_USER_MODEL = 'news.cpUser'
>
> however, after running
>
> $ python manage syncdb
>
> i get
>
> NameError: name 'settings' is not defined
>
> What am i doing wrong?
>
>
>
> best regards,
> Michael
>
> --
> 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: django 1.5, subclass AbstractUser -> NameError: name 'settings' is not defined

2012-11-02 Thread Michael Muster
On Fri, Nov 02, 2012 at 04:59:35PM +0800, Russell Keith-Magee wrote:
> Can you run:
> 
> ./manage syncdb --traceback
> 
> so we can get the full context of the error message?
> 

Sure, here it is:

:~/www/project$ python manage.py syncdb --traceback
Traceback (most recent call last):
  File "/usr/local/bin/django/django/core/management/base.py", line 222, in 
run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/local/bin/django/django/core/management/base.py", line 251, in 
execute
self.validate()
  File "/usr/local/bin/django/django/core/management/base.py", line 277, in 
validate
num_errors = get_validation_errors(s, app)
  File "/usr/local/bin/django/django/core/management/validation.py", line 34, 
in get_validation_errors
for (app_name, error) in get_app_errors().items():
  File "/usr/local/bin/django/django/db/models/loading.py", line 165, in 
get_app_errors
self._populate()
  File "/usr/local/bin/django/django/db/models/loading.py", line 71, in 
_populate
self.load_app(app_name, True)
  File "/usr/local/bin/django/django/db/models/loading.py", line 95, in load_app
models = import_module('.models', app_name)
  File "/usr/local/bin/django/django/utils/importlib.py", line 35, in 
import_module
__import__(name)
  File "/home/michael/www/project/news/models.py", line 27, in 
class News(models.Model):
  File "/home/michael/www/project/news/models.py", line 28, in News
author = models.ForeignKey(settings.AUTH_USER_MODEL)
NameError: name 'settings' is not defined
NameError: name 'settings' is not defined


What i forgot in my first post is 
that i reference the user model like this:

author = models.ForeignKey(settings.AUTH_USER_MODEL)

So if i remove that line the syncdb command works 
just fine.

-- 
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 1.5, subclass AbstractUser -> NameError: name 'settings' is not defined

2012-11-02 Thread Raffaele Salmaso
On Fri, Nov 2, 2012 at 10:11 AM, Michael Muster
 wrote:
>   File "/home/michael/www/project/news/models.py", line 28, in News
> author = models.ForeignKey(settings.AUTH_USER_MODEL)
> NameError: name 'settings' is not defined
> NameError: name 'settings' is not defined
did you forget to include
from django.conf import settings
in /home/michael/www/project/news/models.py?

--
| Raffaele Salmaso
| http://salmaso.org
| https://bitbucket.org/rsalmaso
| http://gnammo.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: django 1.5, subclass AbstractUser -> NameError: name 'settings' is not defined

2012-11-02 Thread Michael Muster
On Fri, Nov 02, 2012 at 10:15:11AM +0100, Raffaele Salmaso wrote:
> did you forget to include
> from django.conf import settings
> in /home/michael/www/project/news/models.py?
> 
> --
> | Raffaele Salmaso

Yep, adding it did it :)

Thanks to both of you!

--
Michael

-- 
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: unable to save ModelForm with primary key change

2012-11-02 Thread Tom Evans
On Thu, Nov 1, 2012 at 7:10 PM, msoulier  wrote:
> On Nov 1, 1:27 pm, Tom Evans  wrote:
>> >> Please show the definition of MyForm.
>>
>> Please do show it.
>
> Sorry, the model was in the previous email, here's the form.
>
>
> class McdLoadForm(forms.ModelForm):
> VERSIONPAT = re.compile(r'^(\d+\.){3}\d+$')
>
> class Meta:
> model = McdLoad
> fields = ('version', 'mcdload', 'fromversions')
>
> def clean(self):
> cleaned_data = super(McdLoadForm, self).clean()
> version = cleaned_data.get('version', '')
> log.debug("cleaned_data: version is %s" % version)
> if version:
> version = re.sub(r'^\s+|\s+$', '', version)
> if not McdLoadForm.VERSIONPAT.match(version):
> raise forms.ValidationError, \
> "Bad version, should be 4-digits separated by
> commas"
> cleaned_data['version'] = version
>
> fromversions = self.cleaned_data.get('fromversions', '')
> if fromversions:
> fromversions = re.sub(r'\s', '', fromversions)
> for version in fromversions.split(','):
> if not McdLoadForm.VERSIONPAT.match(version):
> raise forms.ValidationError, \
> "Bad version, should be 4-digits separated by
> commas"
> cleaned_data['fromversions'] = fromversions
>
> log.debug("clean: returning %s" % cleaned_data)
> return cleaned_data
>

Hmm, looks ok.. do you end up with two entries in the DB, one with the
old primary key, and one with the new primary key?

Personally, I don't use natural primary keys with Django, I always let
it create an 'id' primary key, and then add a unique key to cover the
natural key, which avoids issues when you need to change the natural
key. The logic in ModelForm looks like this:

Update fields in the model with fields from the form
Save the instance:
   Does the instance have a primary key?
 Does that primary key exist in the database?
   Persist changes with UPDATE query
 Else
   Create new entry with INSERT query

If you do this yourself in the shell, you will see that you end up
with two objects. Eg, for this model (chosen as it is a simply model,
no constraints other than primary key):

class PropertyValue(models.Model):
   user = models.ForeignKey('User')
   value = models.CharField(max_length=256)

and then create an instance of it, change the primary key, and save
it, the value is duplicated, not updated.

>>> PropertyValue.objects.create(user=u, value='hello')

>>> PropertyValue.objects.filter(user=u, value='hello').count()
1
>>> instance=PropertyValue.objects.filter(user=u, value='hello').get()
>>> instance.id
67L
>>> instance.id = 1234567
>>> instance.save()
>>> PropertyValue.objects.filter(user=u, value='hello').count()
2


Hope that helps explain what is happening.

Cheers

Tom

-- 
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: Help with Custom model field and Custom validation for EmailField().

2012-11-02 Thread Chris Pagnutti
Hi.  I'm pretty new to Django too, so someone else probably has a better 
idea.  But I think that on the server side, you can handle additional 
validation in the view that handles the form submission (i.e. the view that 
the "action" attribute in your form points to).  You can probably attach 
errors to the form in the view too, so if the form data is invalid you can 
display the errors back to the client.

On Friday, November 2, 2012 4:36:20 AM UTC-4, Dilip M wrote:
>
> Hi,
>
> I am new to Django. Went through docs before posting this.. I have a model 
> and form like this.
>
> models.py:
>
> class Recipients(models.Model):
>  dev = models.EmailField()
>  qa = models.EmailField()
>  cc = models.MultipleEmailField()
>
> forms.py:
>
> class RecipientsForm(forms.ModelForm):
>
> class Meta:
> model = Recipients
>
>
> Now I want to,
>
> 1. Add *additional* validation for models.EmailField(). Something like 
> check if email id entered exists in LDAP db.
> 2. Create new model custom field MultipleEmailField(), which would split 
> emails separated by comma and uses modified validation of 
> models.EmailField() done in step 1.
>
> I am going through docs, but not able to figure out how to put things 
> together! Here is what I understood.
>
> MultipleEmailField() should go in /fields.py. But how to 
> make it to run default validation of models.EmailField() and than do custom 
> validation?
>
>
> Any help appreciated..
>
>
> Thanks. Dilip
>

-- 
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/-/ph4KCnq6yCcJ.
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: haystack problem - already registered error

2012-11-02 Thread Laxmikant Gurnalkar

Hey Any Solution on this ?  
On Wednesday, September 15, 2010 4:53:26 AM UTC+5:30, Kenneth Gonsalves 
wrote:
>
> hi,
>
> I have installed haystack with xapian backend. My relevant code is like
> this:
>
> import haystack
> haystack.autodiscover()
>
> from haystack.indexes import *
> from haystack import site
> from web.models import Stock
>
> class StockIndex(RealTimeSearchIndex):
> text = CharField(document=True, use_template=True)
>
> stockist = CharField(model_attr='stockist')
> location = CharField(model_attr='location')
>
> def get_queryset(self):
> return Stock.objects.all()
>
> site.register(Stock, StockIndex)
>
> but on runserver (python2.6, django-trunk, fedora12):
>
> [lawgon@xlquest clearplus]$ python manage.py
> runserver  
> Traceback (most recent call
> last): 
>  
>   File "manage.py", line 11, in
>
>  
>
> execute_manager(settings) 
>   
>   File
> "/usr/lib/python2.6/site-packages/django/core/management/__init__.py",
> line 438, in execute_manager  
>
> utility.execute() 
>   
>   File
> "/usr/lib/python2.6/site-packages/django/core/management/__init__.py",
> line 379, in execute  
>
> self.fetch_command(subcommand).run_from_argv(self.argv)   
>   
>   File
> "/usr/lib/python2.6/site-packages/django/core/management/base.py", line
> 191, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File
> "/usr/lib/python2.6/site-packages/django/core/management/base.py", line
> 209, in execute
> translation.activate('en-us')
>   File
> "/usr/lib/python2.6/site-packages/django/utils/translation/__init__.py",
> line 66, in activate
> return real_activate(language)
>   File "/usr/lib/python2.6/site-packages/django/utils/functional.py",
> line 55, in _curried
> return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
>   File
> "/usr/lib/python2.6/site-packages/django/utils/translation/__init__.py",
> line 36, in delayed_loader
> return getattr(trans, real_name)(*args, **kwargs)
>   File
> "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", 
> line 193, in activate
> _active[currentThread()] = translation(language)
>   File
> "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", 
> line 176, in translation
> default_translation = _fetch(settings.LANGUAGE_CODE)
>   File
> "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", 
> line 159, in _fetch
> app = import_module(appname)
>   File "/usr/lib/python2.6/site-packages/django/utils/importlib.py",
> line 35, in import_module
> __import__(name)
>   File "/usr/lib/python2.6/site-packages/haystack/__init__.py", line
> 124, in 
> handle_registrations()
>   File "/usr/lib/python2.6/site-packages/haystack/__init__.py", line
> 121, in handle_registrations
> search_sites_conf = __import__(settings.HAYSTACK_SITECONF)
>   File "/home/lawgon/clearplus/web/search_indexes.py", line 17, in
> 
> site.register(Stock, StockIndex)
>   File "/usr/lib/python2.6/site-packages/haystack/sites.py", line 45, in
> register
> raise AlreadyRegistered('The model %s is already registered' %
> model.__class__)
> haystack.exceptions.AlreadyRegistered: The model  'django.db.models.base.ModelBase'> is already registered
>
> -- 
> regards
> Kenneth Gonsalves
>
>

-- 
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/-/8jr3Jed1cVEJ.
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: Help with Custom model field and Custom validation for EmailField().

2012-11-02 Thread Dilip M
On Fri, Nov 2, 2012 at 5:52 PM, Chris Pagnutti  wrote:
> Hi.  I'm pretty new to Django too, so someone else probably has a better
> idea.  But I think that on the server side, you can handle additional
> validation in the view that handles the form submission (i.e. the view that
> the "action" attribute in your form points to).  You can probably attach
> errors to the form in the view too, so if the form data is invalid you can
> display the errors back to the client.

Yeah! I think that is one of the way.  :) But I guess it can done at
some level at Model validation..

The doc says 
https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/#overriding-the-clean-method
 "if you would like to override the clean() method and maintain the
_default validation_, you must call the parent class's clean()
method."

A example would really help...

:)


> On Friday, November 2, 2012 4:36:20 AM UTC-4, Dilip M wrote:
>>
>> Hi,
>>
>> I am new to Django. Went through docs before posting this.. I have a model
>> and form like this.
>>
>> models.py:
>>
>> class Recipients(models.Model):
>>  dev = models.EmailField()
>>  qa = models.EmailField()
>>  cc = models.MultipleEmailField()
>>
>> forms.py:
>>
>> class RecipientsForm(forms.ModelForm):
>>
>> class Meta:
>> model = Recipients
>>
>>
>> Now I want to,
>>
>> 1. Add *additional* validation for models.EmailField(). Something like
>> check if email id entered exists in LDAP db.
>> 2. Create new model custom field MultipleEmailField(), which would split
>> emails separated by comma and uses modified validation of
>> models.EmailField() done in step 1.
>>
>> I am going through docs, but not able to figure out how to put things
>> together! Here is what I understood.
>>
>> MultipleEmailField() should go in /fields.py. But how to
>> make it to run default validation of models.EmailField() and than do custom
>> validation?
>>
>>
>> Any help appreciated..

-- 
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: unable to save ModelForm with primary key change

2012-11-02 Thread Michael P. Soulier
On 02/11/12 Tom Evans said:

> Hmm, looks ok.. do you end up with two entries in the DB, one with the
> old primary key, and one with the new primary key?

No, and I expected to.

> Personally, I don't use natural primary keys with Django, I always let
> it create an 'id' primary key, and then add a unique key to cover the
> natural key, which avoids issues when you need to change the natural
> key. The logic in ModelForm looks like this:

I'm going to go that route, but this seems like a bug, so I'll report it.

Mike

-- 
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: Help with Custom model field and Custom validation for EmailField().

2012-11-02 Thread Chris Pagnutti
Again, I'm not sure, but I think to do it at Model validation level you'd 
have to modify some of the django core files themselve.  I think what 
you're looking for is in django.core.validators (in my install this file is 
at /lib/python2.7/site-packages/django/core/validators.py, or you can just 
search for validators.py on your system)  But I've had my own troubles that 
I thought I could solve by modifying the django files themselves (and it 
works), but everyone that helped me advised that this is not the best way 
to do it, because future updates of django itself will break your changes.

I think the best way to do it is in your view that handles the form.  For 
point 2., just make you MultipleEmailField() a CharField instead, and 
validate it in your view.  For example, you could do something like this 
(note that I'm pulling lots of this from the docs and here 
http://stackoverflow.com/questions/3217682/checking-validity-of-email-in-django-python,
 
and I haven't tested it)

from django.shortcuts import render
from django.http import HttpResponseRedirect

def your_form_handling_view(request):
if request.method == 'POST': # If the form has been submitted...
form = YourForm(request.POST) # A form that you created in your 
forms.py
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data...get all the fields 
that require further validation
your_multipleemail_field = 
form.cleaned_data['your_multipleemail_field']
# perform the extra validation here, for example
extra_validation_passes = True
for email in your_multipleemail_field.split(','):
if email_id_exists(email) and not(validateEmail(email)): 
 #assuming some_field is the email id and email_id_exists() is your 
function that validates it
#Create your custom errors here
form.your_multipleemail_field.errors = "Email id 
already exists in LDAP or is invalid"
extra_validation_passes = False
if extra_validation_passes:
return HttpResponseRedirect('/thanks/') # Redirect after 
POST
return render(request, 'template_with_your_form_on_it.html', 
{'form': form,}) #Now this form goes back to the template with your custom 
errors.

else:
form = YourForm() # An unbound form

return render(request, 'template_with_your_form_on_it.html', {'form': 
form,})

This is a separate global function you might want to put somewhere other 
than views.py (maybe models.py, but don't forget to import it in views.py 
if you do this)

def validateEmail( email ):
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
try:
validate_email( email )
return True
except ValidationError:
return False


Again, not sure if this works, I've never added custom errors to a form 
like this, but I think forms are normal objects and if the .errors are just 
strings, I don't see why it wouldn't work. In fact it probably doesn't work 
but it might give you some ideas.  Of course, you could split the 
conditional "if email_id_exists(email) and not(validateEmail(email)):" to 
test them separately to give more precise error messages.

Hope that helps.

On Friday, November 2, 2012 4:36:20 AM UTC-4, Dilip M wrote:

> Hi,
>
> I am new to Django. Went through docs before posting this.. I have a model 
> and form like this.
>
> models.py:
>
> class Recipients(models.Model):
>  dev = models.EmailField()
>  qa = models.EmailField()
>  cc = models.MultipleEmailField()
>
> forms.py:
>
> class RecipientsForm(forms.ModelForm):
>
> class Meta:
> model = Recipients
>
>
> Now I want to,
>
> 1. Add *additional* validation for models.EmailField(). Something like 
> check if email id entered exists in LDAP db.
> 2. Create new model custom field MultipleEmailField(), which would split 
> emails separated by comma and uses modified validation of 
> models.EmailField() done in step 1.
>
> I am going through docs, but not able to figure out how to put things 
> together! Here is what I understood.
>
> MultipleEmailField() should go in /fields.py. But how to 
> make it to run default validation of models.EmailField() and than do custom 
> validation?
>
>
> Any help appreciated..
>
>
> Thanks. Dilip
>

-- 
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/-/O7a9stFORSUJ.
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: Help with Custom model field and Custom validation for EmailField().

2012-11-02 Thread Chris Pagnutti
Ahh.  Just saw your link to overriding the clean() method.  So you could 
put all the same logic above into the clean() method instead.

On Friday, November 2, 2012 4:36:20 AM UTC-4, Dilip M wrote:
>
> Hi,
>
> I am new to Django. Went through docs before posting this.. I have a model 
> and form like this.
>
> models.py:
>
> class Recipients(models.Model):
>  dev = models.EmailField()
>  qa = models.EmailField()
>  cc = models.MultipleEmailField()
>
> forms.py:
>
> class RecipientsForm(forms.ModelForm):
>
> class Meta:
> model = Recipients
>
>
> Now I want to,
>
> 1. Add *additional* validation for models.EmailField(). Something like 
> check if email id entered exists in LDAP db.
> 2. Create new model custom field MultipleEmailField(), which would split 
> emails separated by comma and uses modified validation of 
> models.EmailField() done in step 1.
>
> I am going through docs, but not able to figure out how to put things 
> together! Here is what I understood.
>
> MultipleEmailField() should go in /fields.py. But how to 
> make it to run default validation of models.EmailField() and than do custom 
> validation?
>
>
> Any help appreciated..
>
>
> Thanks. Dilip
>

-- 
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/-/h1CS3km1y2wJ.
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: no Polls in the admin page

2012-11-02 Thread Zakk Ng
Actually the the admin.py as mentioned above is required.
If you have coded the model for Poll app then make sure the command *python 
manage.py syncdb *is executed.

On Friday, November 2, 2012 1:59:18 AM UTC+7, Mihail Mihalache wrote:
>
> I have followed the django tutorial up to part 2 - 
> https://docs.djangoproject.com/en/1.4/intro/tutorial02/ .
> Everything worked fine, until I couldn't see the Polls entry on the admin 
> page. I have checked that I have done everything mentioned in the tutorial. 
> I get no error whatsoever. I have no idea what's wrong.
> There is a *polls* entry INSTALLED_APPS.
>

-- 
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/-/M7degCNn_54J.
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: compiler

2012-11-02 Thread Bill Freeman
Surely the error message included a line number?

Also, probably not related, but check that there is no whitespace after
your line ending back-slashes.  (Hint it is safer to put the opening triple
quote before the backslash, and safer yet to put the triple quoted string
in a pare of parentheses, the opening one where you have the backslash.)

On Wed, Oct 31, 2012 at 3:28 AM, Markus Christen  wrote:

> Good Morning
> I have downloaded files, that can helps by my mssql-odbc connection. This
> is my downloaded file:
>
> http://code.google.com/p/django-pyodbc/source/browse/trunk/sql_server/pyodbc/compiler.py?r=190
>
> On lines 188 and 273, i become the message "'return' outside of function".
> It's not a space/tab fail, i have checked this.
> How can i fix this?
>
> --
> 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/-/uvBBHw13tokJ.
> 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.



Confusion with translations

2012-11-02 Thread Santiago Basulto
Hello people,

i'm having some difficult time with translation and I18N. I'm using in
my project django-user-accounts (from Pinax) but I can't translate the
strings there.

When I call manage.py makemessages -l es_AR I don't see translation
for this app ("account"). I've got installed correctly. Also, how can
I do to translate the strings contained in .py files. For example,
check out forms module:
https://github.com/pinax/django-user-accounts/blob/master/account/forms.py#L29

What am I missing?

Thank you very much.

--
Santiago Basulto.-

-- 
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 Development Model

2012-11-02 Thread Smriti Patodi
 

Hello Dennis,

Yes you are right..I am looking for how the Django effort itself is 
managed by the developers and the Django community in general? 

I want to get more information on:

- how Django team gathers requirements for each release

- how does the planning go on for each enhancement/release

- how the team members communicate about their progress(are their any 
formal checkpoints within a release?)

-what is the process of code review and approval, who all are involved

- how about the test planning, are the test plans developed prior to the 
implementation or are they done simultaneously

- and about the estimate of time and resource for the release, do you use 
any estimation techniques or how is it done
If you could some insight on these area or you could let me know of any 
documents/websites where I can find this information.

Thanks
Smriti
On Sunday, October 28, 2012 8:26:33 PM UTC-7, Dennis Lee Bieber wrote:
>
> On Sun, 28 Oct 2012 13:39:52 -0700 (PDT), Smriti Patodi 
> > declaimed the following in 
> gmane.comp.python.django.user: 
>
> > I am a MSIS student at Santa Clara University, CA. My team has chosen 
> > Django to work on for our Software Project Management course. 
>
> Your inquiry is slightly ambiguous. 
>
> Are you intending to /implement/ some "software project 
> management" 
> application /using/ Django? 
>
> > I was wondering if there is some place where I can find documentation 
> > related to Django's Software Development process/model. 
>
> Or are you, instead, asking how the Django effort itself is 
> managed 
> by the developers? Which is how I interpret the above statement. 
>
> {I believe the other two responses currently extant interpreted 
> your 
> request as the former -- you wish to implement a project management 
> application using Django. [I'd also hope that a candidate in a Master's 
> degree program in IS would have encountered relational databases by now 
> ]} 
> -- 
> Wulfraed Dennis Lee Bieber AF6VN 
> wlf...@ix.netcom.com 
> HTTP://wlfraed.home.netcom.com/ 
>
>

-- 
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/-/9rVD2a5r74QJ.
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 Development Model

2012-11-02 Thread Elena Williams
Smriti,

If you're really interested from the "horse's mouth" -- I'd suggest
googling DjangoCon and DjangoCon EU recordings (they are often on
blip.tvbut the most recent ones were put up by
youtube.com/jessenoller.

Most DjangoCon have a core-team sit-down and/or fireside chat with BDFL/s
and this is really informative on how the Django internal design/decision
making processes really work.

Also Russell Keith-Magee's "No, Bad Pony" talk which he re-gave recently at
PyCon AU, but had previously given at DjangoCon would probably answer some
of your questions also.

Regards.



---
Elena :)
@elequ
04022 90172



On Sat, Nov 3, 2012 at 10:58 AM, Smriti Patodi wrote:

> Hello Dennis,
>
> Yes you are right..I am looking for how the Django effort itself is
> managed by the developers and the Django community in general?
>
> I want to get more information on:
>
> - how Django team gathers requirements for each release
>
> - how does the planning go on for each enhancement/release
>
> - how the team members communicate about their progress(are their any
> formal checkpoints within a release?)
>
> -what is the process of code review and approval, who all are involved
>
> - how about the test planning, are the test plans developed prior to the
> implementation or are they done simultaneously
>
> - and about the estimate of time and resource for the release, do you use
> any estimation techniques or how is it done
> If you could some insight on these area or you could let me know of any
> documents/websites where I can find this information.
>
> Thanks
> Smriti
> On Sunday, October 28, 2012 8:26:33 PM UTC-7, Dennis Lee Bieber wrote:
>>
>> On Sun, 28 Oct 2012 13:39:52 -0700 (PDT), Smriti Patodi
>>  declaimed the following in
>> gmane.comp.python.django.user:
>>
>> > I am a MSIS student at Santa Clara University, CA. My team has chosen
>> > Django to work on for our Software Project Management course.
>>
>> Your inquiry is slightly ambiguous.
>>
>> Are you intending to /implement/ some "software project
>> management"
>> application /using/ Django?
>>
>> > I was wondering if there is some place where I can find documentation
>> > related to Django's Software Development process/model.
>>
>> Or are you, instead, asking how the Django effort itself is
>> managed
>> by the developers? Which is how I interpret the above statement.
>>
>> {I believe the other two responses currently extant interpreted
>> your
>> request as the former -- you wish to implement a project management
>> application using Django. [I'd also hope that a candidate in a Master's
>> degree program in IS would have encountered relational databases by now
>> ]}
>> --
>> Wulfraed Dennis Lee Bieber AF6VN
>> wlf...@ix.netcom.com
>> HTTP://wlfraed.home.netcom.**com/
>>
>>  --
> 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/-/9rVD2a5r74QJ.
> 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: GeometryField.geography = True Syntax Help GIS Model

2012-11-02 Thread JJ Zolper
Wait so does anyone know how to do this?

I posted this a long time ago.

How do I define a geography field? I need a geography column so I can 
perform geographic queries on it and the documentation doesn't give me 
a definitive way on how to do it.

Would it be like:

city = models.CharField(max_length=50, GeometryField.geography = true)

???


On Saturday, October 20, 2012 1:22:32 PM UTC-4, JJ Zolper wrote:
>
> Hello everyone,
>
> So I've decided for my GeoDjango application I want WGS84 along with a 
> geography database column, rather than geometry.
>
> I was reading here:
>
> https://docs.djangoproject.com/en/1.4/ref/contrib/gis/model-api/#geography
>
> GeometryField.geography
>
> If set to True, this option will create a database column of type 
> geography, rather than geometry. Please refer to the geography 
> type
>  section 
> below for more details.
>
>
> that to set up a new column as geography I had to 
> set GeometryField.geography = True.
>
> I am unsure of the syntax of how to do this? There was no example given. 
> Or where to properly place this line?
>
> Here is the model.py file I am working on. If you could tell me where to 
> fit this in that would be great?
>
>
> from django.contrib.gis.db import models
>
> class Artist(models.Model):
> name = models.CharField(max_length=30)
> genre = models.CharField(max_length=30)
> city = models.CharField(max_length=60)
> state = models.CharField(max_length=30)
> country = models.CharField(max_length=50)
> website = models.URLField()
> objects = models.GeoManager()
>
> def __unicode__(self):
>return self.name
>
>
>
> Thanks so much,
>
> JJ
>

-- 
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/-/tWBJBDuXZzYJ.
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 Development Model

2012-11-02 Thread Russell Keith-Magee
On Sat, Nov 3, 2012 at 7:58 AM, Smriti Patodi wrote:

> Hello Dennis,
>
> Yes you are right..I am looking for how the Django effort itself is
> managed by the developers and the Django community in general?
>
> I want to get more information on:
>
> - how Django team gathers requirements for each release
>
> - how does the planning go on for each enhancement/release
>
> - how the team members communicate about their progress(are their any
> formal checkpoints within a release?)
>
> -what is the process of code review and approval, who all are involved
>
> - how about the test planning, are the test plans developed prior to the
> implementation or are they done simultaneously
>
> - and about the estimate of time and resource for the release, do you use
> any estimation techniques or how is it done
> If you could some insight on these area or you could let me know of any
> documents/websites where I can find this information.


Hi Smriti,

For context: I'm a 6 year veteran of the Django core team, and President of
the Django Software Foundation.

The short version -- everything you learned in your Software Project
Management class is wrong :-)

The longer version -- Open source projects operate under a different set of
criteria to textbook commercial projects. For the most part, this is due to
the fact that in an open source project (at least, in a volunteer run
project list Django), we don't have a known resourcing availability.
There's no point making grand plans, because there's no guarantee that
you'll have enough resources.

As a result, we don't really have a formal requirements gathering process.
The features that get added in any given release are those features that
someone in the community is enthused enough to build, that can garner
enough support from the core team.

Some of Django's development process has been documented:

https://docs.djangoproject.com/en/1.4/internals/contributing/
https://docs.djangoproject.com/en/1.4/internals/release-process/

However, some of these documents are "in principle" documents that don't
necessarily always follow through to "in practice".

If this is something you're doing as a research project and you've got
specific questions, I'm happy to jump on Skype for an hour or two for an
in-person discussion. Email me off-list if this is something you're
interested in.

Yours,
Russ Magee %-)

-- 
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: GeometryField.geography = True Syntax Help GIS Model

2012-11-02 Thread Christiano Anderson
First of all, you have to create a geo database. Postgis (a PostgreSQL
extension) is the best choice.

After that, you have to define some geography fields and import your data,
shape files (shp), etc.

GeoDjango Tutorial provides all the steps to get it done.

https://docs.djangoproject.com/en/dev/ref/contrib/gis/tutorial/

If you are not familiar with geo concepts, I recommend to take a look at
http://geodjango.org/presentations/

Hope that helps you




On Fri, Nov 2, 2012 at 11:30 PM, JJ Zolper  wrote:

> Wait so does anyone know how to do this?
>
> I posted this a long time ago.
>
> How do I define a geography field? I need a geography column so I can
> perform geographic queries on it and the documentation doesn't give me
> a definitive way on how to do it.
>
> Would it be like:
>
> city = models.CharField(max_length=**50, GeometryField.geography = true)
>
> ???
>
>
> On Saturday, October 20, 2012 1:22:32 PM UTC-4, JJ Zolper wrote:
>>
>> Hello everyone,
>>
>> So I've decided for my GeoDjango application I want WGS84 along with a
>> geography database column, rather than geometry.
>>
>> I was reading here:
>>
>> https://docs.djangoproject.**com/en/1.4/ref/contrib/gis/**
>> model-api/#geography
>>
>> GeometryField.geography
>>
>> If set to True, this option will create a database column of type
>> geography, rather than geometry. Please refer to the geography 
>> type
>>  section
>> below for more details.
>>
>>
>> that to set up a new column as geography I had to
>> set GeometryField.geography = True.
>>
>> I am unsure of the syntax of how to do this? There was no example given.
>> Or where to properly place this line?
>>
>> Here is the model.py file I am working on. If you could tell me where to
>> fit this in that would be great?
>>
>>
>> from django.contrib.gis.db import models
>>
>> class Artist(models.Model):
>> name = models.CharField(max_length=**30)
>> genre = models.CharField(max_length=**30)
>> city = models.CharField(max_length=**60)
>> state = models.CharField(max_length=**30)
>> country = models.CharField(max_length=**50)
>> website = models.URLField()
>> objects = models.GeoManager()
>>
>> def __unicode__(self):
>>return self.name
>>
>>
>>
>> Thanks so much,
>>
>> JJ
>>
>  --
> 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/-/tWBJBDuXZzYJ.
> 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.
>



-- 
Christiano Anderson | http://christiano.me/
http://twitter.com/dump

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