Re: how to semi-automate a choice in contrib.admin

2012-11-01 Thread Mike Dewhirst

On 2/11/2012 3:09pm, Mike Dewhirst wrote:

If a user leaves a compulsory (blank=False) field empty in the Admin app
I want to check the value of a different field and depending on that
value either ...

do nothing and let the system complain it needs data

or

fill in some appropriate data so it is no longer empty

I have tried doing this in clean() on the model but without luck.

On the other hand, clean() will happily insert my data if the field is
adjusted to blank=True but that defeats the purpose of blank=False.

How I can make the field blank=True and raise the exact same exception
to emulate blank=False if the field is left empty when my logic says it
should complain?


Raising a ValidationError in clean() when blank=True and the field is 
empty does display the same error as if blank=False but ...


1. The error appears at the top of the page instead of just above the 
field in question.


2. I can only get one error at a time.

Any suggestions?

Thanks


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.



how to semi-automate a choice in contrib.admin

2012-11-01 Thread Mike Dewhirst
If a user leaves a compulsory (blank=False) field empty in the Admin app 
I want to check the value of a different field and depending on that 
value either ...


do nothing and let the system complain it needs data

or

fill in some appropriate data so it is no longer empty

I have tried doing this in clean() on the model but without luck.

On the other hand, clean() will happily insert my data if the field is 
adjusted to blank=True but that defeats the purpose of blank=False.


How I can make the field blank=True and raise the exact same exception 
to emulate blank=False if the field is left empty when my logic says it 
should complain?


Thanks

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

2012-11-01 Thread Sandeep kaur
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.



Re: Problem with formset

2012-11-01 Thread Sandeep kaur
On Fri, Nov 2, 2012 at 1:41 AM, Lachlan Musicman  wrote:

>
> I think you are saying you don't understand my response? I'm asking if the
> problem is fixed by replacing formset.save() - with cd.save(), since you
> have cd = formset.cleaned_data but no other instances of cd, making it kinda
> useless?
>
> should here be a cd = ObjectName() in there?
>
According to me, he need not to assign cd, because it is then not used
anywhere to clean the form data.

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



Re: Help me choose OS for django server

2012-11-01 Thread Nikolas Stevenson-Molnar
Whatever gives you separate physical resources. The idea is to prevent your app 
and static content delivery from interfering (i.e., consuming CPU, memory, 
bandwidth) with each other. The cheapest and most effective way to accomplish 
this is using a CDN or something like Amazon's S3. For relatively light usage, 
it will only cost you a few dollars a month, and you don't need to worry about 
setting up and maintaining a separate server yourself.

_Nik

On Nov 1, 2012, at 12:06 PM, Chris Pagnutti wrote:

> So by "another server entirely" you mean to actually subscribe to another 
> hosting service (or a second account on my current service)?  I'm sure it's 
> in the docs if I look, but how would I deal with media uploads that way?
> 
> On Tuesday, October 30, 2012 3:50:30 PM UTC-4, Chris Pagnutti wrote:
> Hi.  I want to set up a production server for a django application.  
> constant.com offers Virtual Private Servers which should give me virtually 
> full control over the server, allowing me to install django and all the stuff 
> I need for my app to run properly.
> 
> First, is this a good idea?  Do you think I can do this securely using the 
> django, apache, and lighttpd docs? or am I asking for trouble?  What are the 
> major security issues I need to be aware of when administering a server?
> 
> Also, if I go this route, I'll need to choose an OS.  I'm running a 
> production server (just Apache + mod_wsgi) using my Arch Linux box, but I 
> don't think arch is the best idea.  I'm sorta trying to decide between CentOS 
> and Ubuntu.  Leaning toward CentOS, but just a little worried it might be 
> missing some of the packages I need.  I've never used CentOS before.  Any 
> advice?
> 
> -- 
> 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/-/UQij5ebLzwYJ.
> 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: Easy way to make all form fields read only?

2012-11-01 Thread Matt Woodward
On Thursday, November 1, 2012 4:33:47 AM UTC-7, Amyth wrote:

> I would suggest you adding Boolean field to your UserProfile model like 
> is_authorized = models.BooleanField(default=False)


Cool -- thanks for the suggestion. As I've said I'm new to the Django world 
but this community rocks! :-) Really appreciate all the suggestions and 
tips I'm getting so far.

-- 
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/-/-yXv4JUztrsJ.
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: Easy way to make all form fields read only?

2012-11-01 Thread Matt Woodward
On Wednesday, October 31, 2012 8:40:10 PM UTC-7, elena wrote:

> I was also going to suggest using crispy forms -- having used it on a 
> recent project I'd strongly recommend it (it's great when it's plugged in 
> to  existing stylings such as: uni-form or bootstrap).
>
> I've used it with ModelForm using Layout() and Field() and it works a 
> treat.
>

Awesome -- thanks for the recommendation. I'll check it out.

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



Re: Problem with formset

2012-11-01 Thread Lachlan Musicman
On Thu, Nov 1, 2012 at 6:32 PM, Satinderpal Singh <
satinder.goray...@gmail.com> wrote:

> On Thu, Nov 1, 2012 at 1:25 AM, Lachlan Musicman wrote:
>
>> On Thu, Nov 1, 2012 at 7:30 AM, Satinderpal Singh
>>  wrote:
>> > I use formset in my views.py file for the forms. It saves the entries
>> from
>> > the form to the database but the problem is that it shows all the
>> previous
>> > forms along with the new form for the new entry. The code for my views
>> file
>> > is given below:
>> >
>> > def chemical_analysis(request):
>> > ChemicalFormSet = modelformset_factory(chem_analysis)
>> > if request.method=='POST':
>> > formset = ChemicalFormSet(request.POST, request.FILES)
>> > if formset.is_valid():
>> > cd = formset.cleaned_data
>> > formset.save()
>>
>> Should that be cd.save()? Where else is cd used?
>
> No other cd is used in this view, and i did not get your above logic,
> cd.save()
>
>>
>>
I think you are saying you don't understand my response? I'm asking if the
problem is fixed by replacing formset.save() - with cd.save(), since you
have cd = formset.cleaned_data but no other instances of cd, making it
kinda useless?

should here be a cd = ObjectName() in there?


L.




> > return
>> HttpResponseRedirect(reverse('Automation.report.views.result_chem'))
>> > else:
>> > return HttpResponse("There was an error with your submission.
>> Please
>> > try again.")
>> > else:
>> > formset = ChemicalFormSet()
>> > return render_to_response('report/report_add_row.html', {'formset':
>> > formset}, context_instance=RequestContext(request))
>> >
>> > Any help will be appreciated.
>> >
>> > --
>> > Satinderpal Singh
>> > http://satindergoraya.blogspot.in/
>> > http://satindergoraya91.blogspot.in/
>> >
>> > --
>> > 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.
>>
>>
>>
>> --
>> ...we look at the present day through a rear-view mirror. This is
>> something Marshall McLuhan said back in the Sixties, when the world
>> was in the grip of authentic-seeming future narratives. He said, “We
>> look at the present through a rear-view mirror. We march backwards
>> into the future.”
>>
>> http://www.warrenellis.com/?p=14314
>>
>> --
>> 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.
>>
>>
>
>
> --
> Satinderpal Singh
> http://satindergoraya.blogspot.in/
> http://satindergoraya91.blogspot.in/
>
> --
> 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.
>



-- 
...we look at the present day through a rear-view mirror. This is something
Marshall McLuhan said back in the Sixties, when the world was in the grip
of authentic-seeming future narratives. He said, “We look at the present
through a rear-view mirror. We march backwards into the future.”

http://www.warrenellis.com/?p=14314

-- 
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: Error: One or more models did not validate:

2012-11-01 Thread Hendrikus Godvliet
This post is solved:
https://groups.google.com/forum/?fromgroups=#!topic/django-users/u8joQF36BvE

Hendrikus Godvliet


Op donderdag 1 november 2012 12:44:29 UTC+2 schreef Hendrikus Godvliet het 
volgende:
>
> Hello Everone
>
> I am new to Django:
>
> I am in the Django tutorials_01 and now in tutorial 02 in the admin part:
>
> when i update the database with:
> # python manage.py syncdb
>
> There is this message:
>
> Error: One or more models did not validate:
> admin.logentry: 'user' has a relation with model  'django.contrib.auth.models.User'>, which has either not been installed or 
> is abstract.
>
>
>
>

-- 
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/-/i8rP-tGSZI0J.
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: Error: One or more models did not validate: admin.logentry: 'user' has a relation with model , which has either not been installed or is abstract.

2012-11-01 Thread Hendrikus Godvliet
Tom thank you for helping me on my way in to Django!

I uncomment: 
INSTALLED_APPS = (
'django.contrib.auth',

and with 
$ python manage.py syncdb 

I still get the eror:
 Error: One or more models did not validate: admin.logentry: 'user' has 
a  relation with model , which 
has either not been installed or is abstract. 

But than I also uncommented:

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',

And everything started to work.


> On Thu, Nov 1, 2012 at 8:02 AM, Hendrikus Godvliet 
> > wrote: 
> > Hello every one 
> > 
> > I am new to Django - I am on Google Python App engine and try to work 
> with 
> > Django to understand more about how Google App engine works. 
> > For that i follow the tutorial on 
> > https://docs.djangoproject.com/en/1.4/intro/tutorial01/ I finist 
> tutorial 01 
> > and started with tutorial 02 the Admin part. 
> > 
> > First of all do i need this admin part to work with Django for a simple 
> app? 
> > 
> > Second: 
> > I get this message with: 
> > $ python manage.py syncdb 
> > Error: One or more models did not validate: admin.logentry: 'user' has a 
> > relation with model , which has 
> > either not been installed or is abstract. 
> > 
>
> The error message says that you have not added "django.contrib.auth" 
> to INSTALLED_APPS in your settings.py, as far as I can tell. 
>
> However, I have no experience of Django on app engine. App engine uses 
> a customized version of Django, since App Engine does not support 
> relational databases. This "django-nonrel" (non relational) may not 
> behave in a way compatible with the tutorial, I don't know. If you are 
> just starting with Django, I would stick to a more standard Django 
> setup. 
>
> Cheers 
>
> Tom 
>

-- 
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/-/gQCcaFANwdUJ.
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: Using RequireJS with Django

2012-11-01 Thread David Hall
I realise that this is an old topic, but I hope this is useful to other 
people looking to use RequireJS with Django.

You should take a look at django-require, which takes care of integrating 
the r.js optimizer with Django. I've just pushed up the 1.0.0 release.

https://github.com/etianen/django-require

It optimises your project using r.js in a post_process step. There's two 
built-in storage classes, and a mixin that can integrate with any other 
django storage backend (for example, S3BotoStorage from django-storages).

It also supports compiling standalone modules using almond.js.

It's a new package, so all feedback gratefully received!

On Tuesday, 28 February 2012 07:11:32 UTC, jpk wrote:
>
> Hi django-users,
>
> I'm working on a django project with a quickly growing javascript
> front-end using backbone.  The backbone application has grown to the
> point where it needs to be split into modules across multiple files.
> I'm looking into RequireJS to do that.
>
> I've done some research on how to best use require in django, but
> haven't found much.  My first stab at this is probably going to be
> more or less: Take the single javascript file I have now, break it
> into AMD modules in a sub-directory of the static directory the single
> file is in, set up require's minification stuff to put the minified
> javascript there in another sub-directory the same static directory,
> then set up templates to conditionally include the source/minified
> javascript for development/production.  Then I'll figure out some
> mechanism to run the minification stuff on the server during
> deployment.
>
> So, what I'm looking for is wisdom related to carrying out that
> process and maintaining it.  Has anyone set up require in a django
> project before, and have any tips to share?  I'd love to hear them!
>
> Thanks
> john
>
> --
> john p. kiffmeyer
>
>

-- 
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/-/YShx_WBt3sYJ.
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-01 Thread msoulier
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

-- 
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 me choose OS for django server

2012-11-01 Thread Chris Pagnutti
So by "another server entirely" you mean to actually subscribe to another 
hosting service (or a second account on my current service)?  I'm sure it's 
in the docs if I look, but how would I deal with media uploads that way?

On Tuesday, October 30, 2012 3:50:30 PM UTC-4, Chris Pagnutti wrote:
>
> Hi.  I want to set up a production server for a django application.  
> constant.com offers Virtual Private Servers which should give me 
> virtually full control over the server, allowing me to install django and 
> all the stuff I need for my app to run properly.
>
> First, is this a good idea?  Do you think I can do this securely using the 
> django, apache, and lighttpd docs? or am I asking for trouble?  What are 
> the major security issues I need to be aware of when administering a server?
>
> Also, if I go this route, I'll need to choose an OS.  I'm running a 
> production server (just Apache + mod_wsgi) using my Arch Linux box, but I 
> don't think arch is the best idea.  I'm sorta trying to decide between 
> CentOS and Ubuntu.  Leaning toward CentOS, but just a little worried it 
> might be missing some of the packages I need.  I've never used CentOS 
> before.  Any advice?
>

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



no Polls in the admin page

2012-11-01 Thread Mihail Mihalache
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/-/67rCDUo8gEwJ.
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: Extend Django UserProfile

2012-11-01 Thread Zoltán Bege
Thank you for your suggestion!

I already done that, the problem is resolved for the moment using "through" 
for m2m model.

On Thursday, November 1, 2012 2:40:37 PM UTC+2, Nicolas Emiliani wrote:
>
>
>
> On Thu, Nov 1, 2012 at 6:29 AM, Zoltán Bege 
> > wrote:
>
>> I created an accounts app in my project, I 'd like to extend users to be 
>> able to work with one or more partners. I need to define one or more admin 
>> user for every partner.
>>
>> This is my accounts/models.py. In this case is_admin is set globally for 
>> all partners, how do I have to set is_admin differently for every partner?
>>
>> class UserProfile(models.Model):
>> partners = models.ManyToManyField('partners.Partner', null = True, 
>> blank = True)
>> user = models.OneToOneField(User)
>> is_admin = models.BooleanField(default = False)
>> 
>> def __unicode__(self):
>> return self.partners
>> 
>> def create_user_profile(sender, instance, created, **kwargs):
>> if created:
>> UserProfile.objects.create(user = instance)
>> 
>> post_save.connect(create_user_profile, sender = User)
>>
>>
> Hi, if you are using the Admin site contrib application you can do this :
>
>
> https://docs.djangoproject.com/en/dev/topics/auth/#adding-userprofile-fields-to-the-admin
>
> That way whenever you create a user, you'll have the inlined form that 
> belongs to 
> your user profile and you can simply check the is_admin checkbox.
>
>
> Thanks!
>>
>> --
>> Zoltán Bege
>>
>> -- 
>> 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/-/x4UAl7Mc-w8J.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> -- 
> Nicolas Emiliani
>
> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>

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



Occasional IntegrityError on m2m fields using PostgreSQL

2012-11-01 Thread Bernardo
Hello guys,

I can't detect any pattern, maybe 1 in each 1000 thousands edit of a 
certain model returns an IntegrityError on a m2m field. Most of the times 
this field wasn't even modified. When a model is saved I believe django 
always wipes the m2m field and then readds the items, right? I saw django 
calls clear() and then add()s the items. My code then fails with:

IntegrityError: duplicate key value violates unique constraint 
"app_model_m2m_field_key"

It seems like the add of items is performed before the items are cleared, 
which is very weird. I've tried to reproduce it but it's very hard, only 
happens occasionally. Any idea what could cause it? Could maybe setting 
auto commit solve this problem? Thanks in advance

Cheers,
Bernardo

-- 
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/-/OtS2XH-XyioJ.
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 me choose OS for django server

2012-11-01 Thread Nikolas Stevenson-Molnar
Apache+mod_wsgi is one solution (the docs also mention several others).
Their main point is that you shouldn't serve static content via Django.
Ideally, you'd serve static content from another server entirely or via
a CDN. If you are serving files + app on the same server, I think it's
fine to use nginx for both since unlike the Apache+mod_wsgi setup, nginx
isn't actually running the Django app, but simply acting as a proxy.

_Nik

On 10/30/2012 6:04 PM, Chris Pagnutti wrote:
> Hi all.  Thanks to everyone for their comments.  If Debian is
> available, I think I like that idea for the OS.
>
> As for server security, I think I had the basics, but there are some
> great points in your replies.  
>
> @Nik:
> Just following the django docs, it recommends Apache+mod_wsgi for the
> django app, and either lighttpd or nginx to serve media.  I liked the
> idea of serving media separately because the app is heavy on video
> streaming.  Is your suggestion to serve both the app and media using
> nginx?  Is this more secure?  Better performance?  Can you please
> point me to some docs that explain how to set up nginx for django?
>  Will google it in the meantime.
>
> Thanks a whole bunch.
>
> On Tuesday, October 30, 2012 3:50:30 PM UTC-4, Chris Pagnutti wrote:
>
> Hi.  I want to set up a production server for a django
> application.  constant.com  offers Virtual
> Private Servers which should give me virtually full control over
> the server, allowing me to install django and all the stuff I need
> for my app to run properly.
>
> First, is this a good idea?  Do you think I can do this securely
> using the django, apache, and lighttpd docs? or am I asking for
> trouble?  What are the major security issues I need to be aware of
> when administering a server?
>
> Also, if I go this route, I'll need to choose an OS.  I'm running
> a production server (just Apache + mod_wsgi) using my Arch Linux
> box, but I don't think arch is the best idea.  I'm sorta trying to
> decide between CentOS and Ubuntu.  Leaning toward CentOS, but just
> a little worried it might be missing some of the packages I need.
>  I've never used CentOS before.  Any advice?
>
> -- 
> 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/-/Z-S0RK7YEicJ.
> 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: unable to save ModelForm with primary key change

2012-11-01 Thread Tom Evans
On Thu, Nov 1, 2012 at 5:15 PM, Michael P. Soulier
 wrote:
> On 01/11/12 Tom Evans said:
>
>> Please show the definition of MyForm.

Please do show it.

-- 
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-01 Thread Michael P. Soulier
On 01/11/12 Tom Evans said:

> Please show the definition of MyForm. I assume you are certain that
> the form is valid, ie you have put breakpoints there (or print
> statements) and form.is_valid() is definitely returning true.

I used MyForm as an example, the actual class is

class McdLoad(models.Model):
"""A model representing an MCD load uploaded to the server, either by the
UI or by a blade."""
version = models.CharField(primary_key=True,
   max_length=32)
mcdload = models.FileField(upload_to='ftproot',
   blank=True)
fromversions = models.CharField(max_length=4096, default='')
remove_load = models.BooleanField(default=False)

def __str__(self):
return "%s:%s" % (self.version, self.fromversions)

class Meta:
db_table = 'mcdloads'

The view code looks like...

mcdload = McdLoad.objects.get(version=version)
if request.method == 'POST':
log.info("in a POST request")
form = McdLoadForm(request.POST, instance=mcdload)
if form.is_valid():
log.debug("yay, the form is valid")
form.save()

The logs indicate that is_valid() returned True.

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

2012-11-01 Thread Tom Evans
On Thu, Nov 1, 2012 at 3:33 PM, msoulier  wrote:
> Hi,
>
> I'm trying to modify a model instance, specifically the field which is
> the model's primary key. When I save, nothing seems to happen.
> Everything in cleaned_data is good, but the model is not updated. No
> exception is thrown, the field isn't updated, nothing.
>
> All I'm doing is
>
> form = MyForm(request.POST, instance=model_instance)
> if form.is_valid():
> form.save()
>
> I'm thinking that this might be an issue with respect to how sqlite
> handles changes to primary key fields. Perhaps I'm handling the change
> incorrectly. Help appreciated.
>
> Using Django 1.4.1 with python-sqlite2 2.6.3 and 3.6.20.
>
> Thanks,
> Mike
>

Please show the definition of MyForm. I assume you are certain that
the form is valid, ie you have put breakpoints there (or print
statements) and form.is_valid() is definitely returning true.

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: Extend Django UserProfile

2012-11-01 Thread Nicolas Emiliani
On Thu, Nov 1, 2012 at 11:42 AM, Zoltán Bege  wrote:

>
>
> On Thursday, November 1, 2012 11:29:38 AM UTC+2, Zoltán Bege wrote:
>>
>> I created an accounts app in my project, I 'd like to extend users to be
>> able to work with one or more partners. I need to define one or more admin
>> user for every partner.
>>
>> This is my accounts/models.py. In this case is_admin is set globally for
>> all partners, how do I have to set is_admin differently for every partner?
>>
>> class UserProfile(models.Model):
>> partners = models.ManyToManyField('**partners.Partner', null = True,
>> blank = True)
>> user = models.OneToOneField(User)
>> is_admin = models.BooleanField(default = False)
>>
>> def __unicode__(self):
>> return self.partners
>>
>> def create_user_profile(sender, instance, created, **kwargs):
>> if created:
>> UserProfile.objects.create(**user = instance)
>>
>> post_save.connect(create_user_**profile, sender = User)
>>
>> Thanks!
>>
>> --
>> Zoltán Bege
>>
>
Zoltàn, sorry but your last reply was only a copy of the first mail, maybe
something happened
with your email client ?



> --
> 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/-/J0DJKVoy-wcJ.
>
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



unable to save ModelForm with primary key change

2012-11-01 Thread msoulier
Hi,

I'm trying to modify a model instance, specifically the field which is
the model's primary key. When I save, nothing seems to happen.
Everything in cleaned_data is good, but the model is not updated. No
exception is thrown, the field isn't updated, nothing.

All I'm doing is

form = MyForm(request.POST, instance=model_instance)
if form.is_valid():
form.save()

I'm thinking that this might be an issue with respect to how sqlite
handles changes to primary key fields. Perhaps I'm handling the change
incorrectly. Help appreciated.

Using Django 1.4.1 with python-sqlite2 2.6.3 and 3.6.20.

Thanks,
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: Extend Django UserProfile

2012-11-01 Thread Zoltán Bege


On Thursday, November 1, 2012 11:29:38 AM UTC+2, Zoltán Bege wrote:
>
> I created an accounts app in my project, I 'd like to extend users to be 
> able to work with one or more partners. I need to define one or more admin 
> user for every partner.
>
> This is my accounts/models.py. In this case is_admin is set globally for 
> all partners, how do I have to set is_admin differently for every partner?
>
> class UserProfile(models.Model):
> partners = models.ManyToManyField('partners.Partner', null = True, 
> blank = True)
> user = models.OneToOneField(User)
> is_admin = models.BooleanField(default = False)
> 
> def __unicode__(self):
> return self.partners
> 
> def create_user_profile(sender, instance, created, **kwargs):
> if created:
> UserProfile.objects.create(user = instance)
> 
> post_save.connect(create_user_profile, sender = User)
>
> Thanks!
>
> --
> Zoltán Bege
>

-- 
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/-/J0DJKVoy-wcJ.
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.



Store a list from a view in template language into a javascript array

2012-11-01 Thread Coulson Thabo Kgathi
Hi guys

how can i Store a list from a view in template language into a javascript 
array


this is how i pass the list from the django view

(The List that i am trying to store in javascript is the household_list)

views.py  


def plot_ward_points(request):
"""Plot points of a selected ward.

Filter points to plot by sending coordinates of a selected ward only to 
the households.html template.

**Template:**

:template:`mochudi_map/templates/household.html`
"""
households_found = False
selected_ward = request.POST.get('ward')
selected_icon = request.POST.get('marker_icon')
netbooks = Producer.objects.all().order_by('name')
households = Household.objects.filter(ward=selected_ward)
household_list = []

for household in households:
lon = household.lon
lat = household.lat
sid = str(household.household_identifier)

household_list.append([lon, lat, sid])

print household_list


for household in households:
lon = household.lon
lat = household.lat
sid = str(household.household)

if households:
households_found = True
return render_to_response(
'households.html', {
'household_list': household_list,
'netbooks': netbooks,
'wards': get_wards_list(),
'households_found': households_found,
'selected_ward': selected_ward,
'selected_icon': selected_icon,
'icons': ICONS
   },
context_instance=RequestContext(request)
)


this is how i was trying to store the list in the template


in the template
--



var house_list = {{household_list}};


for (var i=0;i

Re: Error: One or more models did not validate: admin.logentry: 'user' has a relation with model , which has either not been installed or is abstract.

2012-11-01 Thread Tom Evans
On Thu, Nov 1, 2012 at 8:02 AM, Hendrikus Godvliet
 wrote:
> Hello every one
>
> I am new to Django - I am on Google Python App engine and try to work with
> Django to understand more about how Google App engine works.
> For that i follow the tutorial on
> https://docs.djangoproject.com/en/1.4/intro/tutorial01/ I finist tutorial 01
> and started with tutorial 02 the Admin part.
>
> First of all do i need this admin part to work with Django for a simple app?
>
> Second:
> I get this message with:
> $ python manage.py syncdb
> Error: One or more models did not validate: admin.logentry: 'user' has a
> relation with model , which has
> either not been installed or is abstract.
>

The error message says that you have not added "django.contrib.auth"
to INSTALLED_APPS in your settings.py, as far as I can tell.

However, I have no experience of Django on app engine. App engine uses
a customized version of Django, since App Engine does not support
relational databases. This "django-nonrel" (non relational) may not
behave in a way compatible with the tutorial, I don't know. If you are
just starting with Django, I would stick to a more standard Django
setup.

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: Extend Django UserProfile

2012-11-01 Thread Nicolas Emiliani
On Thu, Nov 1, 2012 at 6:29 AM, Zoltán Bege  wrote:

> I created an accounts app in my project, I 'd like to extend users to be
> able to work with one or more partners. I need to define one or more admin
> user for every partner.
>
> This is my accounts/models.py. In this case is_admin is set globally for
> all partners, how do I have to set is_admin differently for every partner?
>
> class UserProfile(models.Model):
> partners = models.ManyToManyField('partners.Partner', null = True,
> blank = True)
> user = models.OneToOneField(User)
> is_admin = models.BooleanField(default = False)
>
> def __unicode__(self):
> return self.partners
>
> def create_user_profile(sender, instance, created, **kwargs):
> if created:
> UserProfile.objects.create(user = instance)
>
> post_save.connect(create_user_profile, sender = User)
>
>
Hi, if you are using the Admin site contrib application you can do this :

https://docs.djangoproject.com/en/dev/topics/auth/#adding-userprofile-fields-to-the-admin

That way whenever you create a user, you'll have the inlined form that
belongs to
your user profile and you can simply check the is_admin checkbox.


Thanks!
>
> --
> Zoltán Bege
>
> --
> 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/-/x4UAl7Mc-w8J.
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



Extend Django UserProfile

2012-11-01 Thread Zoltán Bege
I created an accounts app in my project, I 'd like to extend users to be 
able to work with one or more partners. I need to define one or more admin 
user for every partner.

This is my accounts/models.py. In this case is_admin is set globally for 
all partners, how do I have to set is_admin differently for every partner?

class UserProfile(models.Model):
partners = models.ManyToManyField('partners.Partner', null = True, 
blank = True)
user = models.OneToOneField(User)
is_admin = models.BooleanField(default = False)

def __unicode__(self):
return self.partners

def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user = instance)

post_save.connect(create_user_profile, sender = User)

Thanks!

--
Zoltán Bege

-- 
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/-/x4UAl7Mc-w8J.
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.



Error: One or more models did not validate: admin.logentry: 'user' has a relation with model , which has either not been installed or is abstract.

2012-11-01 Thread Hendrikus Godvliet
Hello every one 

I am new to Django - I am on Google Python App engine and try to work with 
Django to understand more about how Google App engine works. 
For that i follow the tutorial on   
https://docs.djangoproject.com/en/1.4/intro/tutorial01/ I finist tutorial 
01 and started with tutorial 02 the Admin part. 

First of all do i need this admin part to work with Django for a simple 
app? 

Second:
I get this message with:
$ python manage.py syncdb
Error: One or more models did not validate: admin.logentry: 'user' has a 
relation with model , which has 
either not been installed or is abstract. 


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



Error: One or more models did not validate:

2012-11-01 Thread Hendrikus Godvliet
Hello Everone

I am new to Django:

I am in the Django tutorials_01 and now in tutorial 02 in the admin part:

when i update the database with:
# python manage.py syncdb

There is this message:

Error: One or more models did not validate:
admin.logentry: 'user' has a relation with model , which has either not been installed or 
is abstract.



-- 
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/-/jJp3Gz2rrXoJ.
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: Easy way to make all form fields read only?

2012-11-01 Thread Amyth Arora
I would suggest you adding Boolean field to your UserProfile model like
is_authorized = models.BooleanField(default=False)

and then in the templates do something like:

{% if user.is_authorized %}



{% else %}





On Thu, Nov 1, 2012 at 9:09 AM, Elena Williams  wrote:

> I was also going to suggest using crispy forms -- having used it on a
> recent project I'd strongly recommend it (it's great when it's plugged in
> to  existing stylings such as: uni-form or bootstrap).
>
> I've used it with ModelForm using Layout() and Field() and it works a
> treat.
>
> ---
> Elena :)
> @elequ
> 04022 90172
>
>
>
> On Thu, Nov 1, 2012 at 7:29 AM, Paul  wrote:
>
>> I used to invest something similar; i wanted to to built a read view next
>> to an update view that looks identical except for that read is obviously
>> read-only. I used crispy-forms to do just that; recently an UneditableField
>> (Layout) was added next to Field.
>> You do however either need to enumerate the model fields in a layout
>> Paul Bormans
>>
>>  --
>> 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/-/5av7W0YQoS8J.
>>
>> 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.
>



-- 
Thanks & Regards


Amyth [Admin - Techstricks]
Email - aroras.offic...@gmail.com, ad...@techstricks.com
Twitter - @mytharora
http://techstricks.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.



From Django using auth_mixin to 1.5 alpha 1 user model

2012-11-01 Thread Thiago Carvalho D' Ávila
Hello,

I am trying to change my app from using auth_mixin (from git) to the new
configurable user model. I've seen no tutorials of how to do that and moved
to auth_mixin long time ago. Does anyone did that and remember the steps?
Any hints?

Tks

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