Re: Support for multiple django annotations?

2012-01-11 Thread girish shabadimath
Try django-cubes

regards,
gms

On Thu, Jan 12, 2012 at 12:05 PM, pradyumna wrote:

> I am trying to use Django aggregation for an existing application that
> uses the following sql query:
>
> select sum(count) as sum_country_count, count(country_abbr) as
> country_cnt,country_abbr from
> (select log_datetime, count(country_abbr) as  count,country_abbr from
> firewall where log_datetime>=DATE('2011-11-09') and
> log_datetime<=DATE('2012-01-08') group by log_datetime,country_abbr)
> country_logs group by country_abbr order by country_abbr;
>
> As you can see, there are multiple aggregations required in this
> django query.
>
> I am able to able to do this:
>
>
> z=Firewall.objects.values('log_datetime','country_abbr').annotate(date_cnt=Count('log_datetime'),country_cnt=Count('country_abbr')).order_by('-
> country_cnt')
>
> and this takes care of inner loop.
>
> If I try to do multiple annotations, django raise error.:
>
>
> z=Firewall.objects.annotate(country_cnt=Count('country_abbr')).annotate(cnt=Count('country_cnt'))
>
> Is there a way in Django where in the above sql query can be handled
> in aggregation clause?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Girish M S

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



Admin GenericTabularInline problem

2012-01-11 Thread MeME
I have such models:

https://bitbucket.org/Memke/webmachinist/src/ae3c2ae9547d/webmachinist/apps/webmachinist/media/models.py

And my adminy.py looks like:

https://bitbucket.org/Memke/webmachinist/src/ae3c2ae9547d/webmachinist/apps/webmachinist/media/admin.py

As you can see I attach Image and Video objects to Gallery through
GalleryItem (generic relation). The problem appears when I want to
manage galleries: I want to have possibility to add images and videos
out of Gallery Admin. I could easily do it reversely - in Image Admin
- but that's not what I want.

Do I have to write some new code? i mean subclassing InlineModelAdmin?
Or it can be done in some easier way?

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



Support for multiple django annotations?

2012-01-11 Thread pradyumna
I am trying to use Django aggregation for an existing application that
uses the following sql query:

select sum(count) as sum_country_count, count(country_abbr) as
country_cnt,country_abbr from
(select log_datetime, count(country_abbr) as  count,country_abbr from
firewall where log_datetime>=DATE('2011-11-09') and
log_datetime<=DATE('2012-01-08') group by log_datetime,country_abbr)
country_logs group by country_abbr order by country_abbr;

As you can see, there are multiple aggregations required in this
django query.

I am able to able to do this:

z=Firewall.objects.values('log_datetime','country_abbr').annotate(date_cnt=Count('log_datetime'),country_cnt=Count('country_abbr')).order_by('-
country_cnt')

and this takes care of inner loop.

If I try to do multiple annotations, django raise error.:

z=Firewall.objects.annotate(country_cnt=Count('country_abbr')).annotate(cnt=Count('country_cnt'))

Is there a way in Django where in the above sql query can be handled
in aggregation clause?

Thanks.

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



Completely decoupled development

2012-01-11 Thread Alec Taylor
What are your thoughts on completely decoupled development?

I have gotten a colleague of mine to work on one whole facet of the
system, whilst I work on the other. In essence, these are two
completely separate systems, on two separate domains.

The plan is to link the two in a signup wizard and display a dashboard
with certain elements of each View.

Given the limited information I have given you, would you recommend
this method of development? - Do you have recommendation on how we
would link everything to a View dashboard?

Thanks for all suggestions,

Alec Taylor

-- 
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: Does anyone know any blogs that write about how to quickly install and deploy a django application on Amazon EC2?

2012-01-11 Thread Alec Taylor
http://pragmaticstartup.wordpress.com/2011/04/02/non-techie-guide-to-setting-up-django-apache-mysql-on-amazon-ec2/

-- 
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 with django Form

2012-01-11 Thread kenneth gonsalves
On Wed, 2012-01-11 at 17:49 -0800, coded kid wrote:
> Please where I’ve I done something wrong? Help me out!

you need to use ModelForm, not create your form in the template. Check
the docs on ModelForm.
-- 
regards
Kenneth Gonsalves

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



Does anyone know any blogs that write about how to quickly install and deploy a django application on Amazon EC2?

2012-01-11 Thread Chen Xu
Hi, everyone:
Does anyone know any blogs that write about how to quickly install and
deploy a django application on Amazon EC2?


Thanks very much
Best regards

-- 
⚡ Chen Xu ⚡

-- 
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 with django Form

2012-01-11 Thread Mario Gudelj
Can you provide your register model?

Is it possible that you've extended the user model and that your username,
password etc is getting stored inside auth_user table?


On 12 January 2012 12:49, coded kid  wrote:

> Hi guys, I’ve been trying to signup using the django form I created.
> Whenever I signup, the form is always saving the id no and not other
> fields like names, username.pasword,email etc. Below are the codes;
> In views.py:
> from django.shortcuts import render_to_response
> from django.http import HttpResponse
> from django.template import RequestContext
> from django.http import HttpResponseRedirect
> from mymeek.meekme import models
> from django.views.decorators.csrf import csrf_exempt
> @csrf_exempt
> def welcome(request):
>#Allow new user reg and login, if failed direct the user to signup
>if request.method=='POST':
>form=models.Register()
>new_user=form.save()
>return HttpResponseRedirect('/logpage/')
>else:
>form=models.Register()
>return render_to_response('mainpage.html',
> {'form':models.Register})
>
> In Models.py
> from django.db import models
> class Register(models.Model):
>names=models.CharField(max_length=50)
>email=models.EmailField('e-mail', blank=False)
>password=models.CharField(max_length=25)
>username=models.CharField(max_length=25)
>country=models.CharField(max_length=40)
>state_province=models.CharField(max_length=30)
>
>def __unicode__(self):
>return self.names
>
> In Template Form:
> 
>  {% csrf_token %}
> Names: 
> Email Address: 
> Password: 
> Username: 
> Country: 
> State: 
> 
> 
> 
> Please where I’ve I done something wrong? Help me out!
>
> --
> 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 me with django Form

2012-01-11 Thread coded kid
Hi guys, I’ve been trying to signup using the django form I created.
Whenever I signup, the form is always saving the id no and not other
fields like names, username.pasword,email etc. Below are the codes;
In views.py:
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template import RequestContext
from django.http import HttpResponseRedirect
from mymeek.meekme import models
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def welcome(request):
#Allow new user reg and login, if failed direct the user to signup
if request.method=='POST':
form=models.Register()
new_user=form.save()
return HttpResponseRedirect('/logpage/')
else:
form=models.Register()
return render_to_response('mainpage.html',
{'form':models.Register})

In Models.py
from django.db import models
class Register(models.Model):
names=models.CharField(max_length=50)
email=models.EmailField('e-mail', blank=False)
password=models.CharField(max_length=25)
username=models.CharField(max_length=25)
country=models.CharField(max_length=40)
state_province=models.CharField(max_length=30)

def __unicode__(self):
return self.names

In Template Form:

 {% csrf_token %}
Names: 
Email Address: 
Password: 
Username: 
Country: 
State: 



Please where I’ve I done something wrong? Help me out!

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



not sure how to unpack a list within a tuple within another list inside the template

2012-01-11 Thread Mario Gudelj
Hi Djangoers,

I have a default dict variable final_d = defaultdict(list) that looks like
this:

[(order1, [customer2, customer1]), (order2, [customer3, customer5,
customer6]) ]

I've tried everything possible inside the template and I can't unpack this
thing. I'm passing final_d to the template inside the dictionary like
this: d = {'final_d':final_d}

This is my template which should I think work from what I've read on SO
and elsewhere:


{% for order, customers in final_d %}


{{ ordder.name }}
Cusotmers

{% for customer in customers %}
{{
customer.name }}
{% endfor %}


{% endfor %}


I have tried absolutely everything and I can't get this to render.

The above code doesn't render a result. if I change {% for order, customers
in final_d %} to {% for order in final_d %} I do get the order details, but
I can't access customer details.

Thank you for your help!

-m

-- 
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: A demo of django-inlinetrans and django-inplaceedit

2012-01-11 Thread Juergen Schackmann
Hi, 
this looks really great.
I have 3 questions for which I would highly appreciate the answers:

1. What is the best way to include some form magic, i.e. sending the 
changes not directly to the model but to a form that does some verification 
and also return the form error messages?
2. If I do not want to send field by field, but possibly a set of fields 
back to the to the server, like the row of a table. Would that be feasible?
3. How would you create a new field on the page/ new object in the model?

Keep up the great work
Juergen

-- 
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/-/rR9BqMnZhEsJ.
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: Class-Based Generic Views (CreateView) - field exclusions and defaults

2012-01-11 Thread Juergen Schackmann
if is use this code, as proposed by russ:
def form_valid(self, form):
self.object.user = ... (something meaningful.. e.g., 
self.request.user)
return super(CreateCampaignView, self).form_valid(form)

i get the error 'NoneType' object has no attribute 'user'. and actually, by 
looking at the source code, that is exactly what is supposed to happen in a 
create view: self.object is set to None, as you can see in BaseCreateView

def post(self, request, *args, **kwargs):
self.object = None
return super(BaseCreateView, self).post(request, *args, **kwargs)

am i the only one having this problem? any help is highly appreciated. 
thanks
juergen

-- 
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/-/QD32CnKdQmsJ.
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: How to avoid "no such column" error when I add a new property to a model?

2012-01-11 Thread Andre Terra
Or use a GUI tool like PgAdmin[0] for PostgreSQL, which is packaged into
most psql distributions.


Cheers,
AT

[0] http://www.pgadmin.org/



On Wed, Jan 11, 2012 at 6:30 PM, Python_Junkie <
software.buy.des...@gmail.com> wrote:

> For those who do not want to use another abstraction module, just use
> sql on the database to add the column.
>
> Look up the alter table command for the database that you are using.
>
> On Jan 11, 5:26 am, callum  wrote:
> > I created an "Article" model with a few simple properties. I ran
> > syncdb, and set up the Django admin site, and added
> > "admin.site.register(Article)" in admin.py. Using the Django admin
> > site, I created an article by filling in the form.
> >
> > I then went into models.py and added another property. I ran syncdb
> > again, ran the server again, then when I opened the Django admin site
> > again, I got the "no such column" error.
> >
> > When I Googled this, the only obvious solutions I found were to reset
> > the app, or at least drop the database table that changed, and start
> > over.
> >
> > But how do I do this without losing my 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.
>
>

-- 
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: How to avoid "no such column" error when I add a new property to a model?

2012-01-11 Thread Python_Junkie
For those who do not want to use another abstraction module, just use
sql on the database to add the column.

Look up the alter table command for the database that you are using.

On Jan 11, 5:26 am, callum  wrote:
> I created an "Article" model with a few simple properties. I ran
> syncdb, and set up the Django admin site, and added
> "admin.site.register(Article)" in admin.py. Using the Django admin
> site, I created an article by filling in the form.
>
> I then went into models.py and added another property. I ran syncdb
> again, ran the server again, then when I opened the Django admin site
> again, I got the "no such column" error.
>
> When I Googled this, the only obvious solutions I found were to reset
> the app, or at least drop the database table that changed, and start
> over.
>
> But how do I do this without losing my 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: Need to examine and act on old vs. new at .save() time

2012-01-11 Thread Jeff
I've just found that the problem is related to my desired
field being M2M.  Anyone know what is going on here? :(

My approach (and Matt's) works fine on a simple CharField field.

class Device(models.Model):
# ...
floor = models.CharField('Floor', max_length=10, blank=True)
# ...

Device : old floor:
Device : new floor: 44

Device : old floor: 44
Device : new floor: 55

Device : old floor: 55
Device : new floor: 22

Device : old floor: 22
Device : new floor:

-- 
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: Need to examine and act on old vs. new at .save() time

2012-01-11 Thread hanks...@gmail.com
 > But is costly when the field in question is foreign, no?  Mine's a
M2M.

Sure. There's probably no way around that, though, except for
judicious use of select_related.

https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related

-- 
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: Need to examine and act on old vs. new at .save() time

2012-01-11 Thread Tom Evans
On Wed, Jan 11, 2012 at 5:22 PM, Jeff  wrote:
> When Device.netgroups (a M2M field) changes, we need to perform
> some python-ldap operations.

Have you considered simply going back to the database to check what
the values currently are? It would be inefficient, but clean and
concise.

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: Need to examine and act on old vs. new at .save() time

2012-01-11 Thread Jeff
On Jan 11, 11:59 am, Andre Terra  wrote:
> The important question here is, what are you trying to achieve, outside of
> the functionality itself? Are you trying to log changes to provide an audit
> trail? If so, there are tools for that.

I wish that's all I was doing.  Then again, I also wish Google Groups
hadn't wrapped my lines at around 60 columns in the previous
post.

The 'audit' looking stuff you're seeing is merely my debugging code to
figure out what the heck is going wrong with my approach.

When Device.netgroups (a M2M field) changes, we need to perform
some python-ldap operations.

-- 
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: Need to examine and act on old vs. new at .save() time

2012-01-11 Thread Andre Terra
The important question here is, what are you trying to achieve, outside of
the functionality itself? Are you trying to log changes to provide an audit
trail? If so, there are tools for that.


Cheers,
AT

On Wed, Jan 11, 2012 at 2:53 PM, Jeff  wrote:

> Matt,
>
> On Jan 10, 5:57 pm, Matt Schinckel  wrote:
> > The way I generally do this type of thing
> > is:https://gist.github.com/1591723
>
> Thanks for the reply!
>
> This looked awfully similar to my logic (although yours is 10x more
> clean),
> but I was excited to implement it this morning.  After doing so, I am
> seeing
> the same behavior:  old_version.foo_field is matching self.foo_field
> no matter
> what I do to foo_field.
>
> https://gist.github.com/1595587
>
> For example, device 'mote' in the database shows no values for field
> netgroups.
> Viewing 'mote' in the Django admin interface, I add a netgroup called
> 'testnetgroup'
> from the list of netgroups available.  I click save.  Viewing 'mote'
> again shows that
> the modification took place -- mote references netgroup
> 'testnetgroup'.
>
> However, the log from that 'save' shows the following bogus
> information:
>
> Device : in custom .save()
> Device : old_version.netgroups.values(): []
> Device : self.netgroups.values(): []
> Device : old does NOT match new
>
> 1. The "new" value is showing incorrectly as an empty list.
> 2. The test shows them the same, but is reporting that they don't even
> match
>
> Viewing device 'mote' again, *removing* the only netgroup from it
> (testnetgroup)
> and re-saving reports similar bogus info:
>
> Device : in custom .save()
> Device : old_version.netgroups.values(): [{'name': u'testnetgroup',
> 'desc': u''}]
> Device : self.netgroups.values(): [{'name': u'testnetgroup', 'desc':
> u''}]
> Device : old does NOT match new
>
> 1. The "new" value is showing incorrectly as [{'name':
> u'testnetgroup', 'desc': u''}] and
> should be an empty list.
> 2. The test shows them the same, but is reporting that they don't even
> match
>
> This should have said:
>
> Device : in custom .save()
> Device : old_version.netgroups.values(): [{'name': u'testnetgroup',
> 'desc': u''}]
> Device : self.netgroups.values(): []
> Device : old does NOT match new
>
> --
> 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: Need to examine and act on old vs. new at .save() time

2012-01-11 Thread Jeff
On Jan 11, 10:03 am, "hanks...@gmail.com"  wrote:
> I go about this a different way, which is to monkeypatch the object
> with the relevant initial values at __init__:
>
> https://gist.github.com/1595055
>
> Saves you a database call.

But is costly when the field in question is foreign, no?  Mine's a M2M.

-- 
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: Need to examine and act on old vs. new at .save() time

2012-01-11 Thread Jeff
Matt,

On Jan 10, 5:57 pm, Matt Schinckel  wrote:
> The way I generally do this type of thing
> is:https://gist.github.com/1591723

Thanks for the reply!

This looked awfully similar to my logic (although yours is 10x more
clean),
but I was excited to implement it this morning.  After doing so, I am
seeing
the same behavior:  old_version.foo_field is matching self.foo_field
no matter
what I do to foo_field.

https://gist.github.com/1595587

For example, device 'mote' in the database shows no values for field
netgroups.
Viewing 'mote' in the Django admin interface, I add a netgroup called
'testnetgroup'
from the list of netgroups available.  I click save.  Viewing 'mote'
again shows that
the modification took place -- mote references netgroup
'testnetgroup'.

However, the log from that 'save' shows the following bogus
information:

Device : in custom .save()
Device : old_version.netgroups.values(): []
Device : self.netgroups.values(): []
Device : old does NOT match new

1. The "new" value is showing incorrectly as an empty list.
2. The test shows them the same, but is reporting that they don't even
match

Viewing device 'mote' again, *removing* the only netgroup from it
(testnetgroup)
and re-saving reports similar bogus info:

Device : in custom .save()
Device : old_version.netgroups.values(): [{'name': u'testnetgroup',
'desc': u''}]
Device : self.netgroups.values(): [{'name': u'testnetgroup', 'desc':
u''}]
Device : old does NOT match new

1. The "new" value is showing incorrectly as [{'name':
u'testnetgroup', 'desc': u''}] and
should be an empty list.
2. The test shows them the same, but is reporting that they don't even
match

This should have said:

Device : in custom .save()
Device : old_version.netgroups.values(): [{'name': u'testnetgroup',
'desc': u''}]
Device : self.netgroups.values(): []
Device : old does NOT match new

-- 
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: Need to examine and act on old vs. new at .save() time

2012-01-11 Thread hanks...@gmail.com
I go about this a different way, which is to monkeypatch the object
with the relevant initial values at __init__:

https://gist.github.com/1595055

Saves you a database call.

-- 
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: Please help me with django form 2.

2012-01-11 Thread J. Cliff Dyer


On Tue, 2012-01-10 at 23:49 -0800, coded kid wrote:
> Hi guys, whenever I signup for my django form, my database is only
> saving the id no and not names, username, email etc. |  #sorry for
> posting it like this. I'm on mobile. Okay. In my views.py, this ( | )
> means next line.@csrf_exempt
> | def welcome(request): | if request.method=='POST': |
> form=models.Register() |new_user=form.save() | return
> HttpResponseRedirect('/logpage/') | else: |form=models.Register()|
> return render_to_response('mainpage.html', {'form':models.Register}) .
> I created an html form and a model with class Register(models.Model):
> 
> names=models.CharField(max_length=50) etc. I hope you get my point?
> Please help.
> 

Your code isn't working because you are saving a model without passing
any attributes to it.

form = model.Register()  # This isn't a form.  It's a model
form.save()  

This will create an empty model, and then when you save it, try to write
that empty model to the database, which will work only if all the fields
are nullable, and will give you a model object with all fields null,
except the primary key, which is automatically populated.

Instead you need to do something like this:

 form = model.Register(names=request.POST['names'])
 form.save()

But really, you should use django's ModelForm, and let django do the
heavy lifting for you.  The django docs can get you started.


-- 
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: Please help me with django form 2.

2012-01-11 Thread 软刀
as I unflod your code
I think may be you should create a Form-class like this:
class RegisterForm(ModelForm):
class Meta:
model = Register


and in your view should be:
@csrf_exempt
def welcome(request):
if request.method=='POST':
form=RegisterForm(request.POST)
new_user=form.save()
return HttpResponseRedirect('/logpage/')
else:
form=RegisterForm()
return render_to_response('mainpage.html', {'form':form})


-- 
as I learning english, any help about english grammar is welcome

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



change min_length in form __init__?

2012-01-11 Thread galgal
Is there any way, to change the field's *min_length* argument inside form 
constructor? That doesn't work:

def __init__(self, *args, **kwargs):
> super(CreateTeamForm, self).__init__(*args, **kwargs)
> self.fields['primary_color'].min_length = 4

-- 
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/-/laN38iWqC-oJ.
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: How to avoid "no such column" error when I add a new property to a model?

2012-01-11 Thread Daniel Roseman
On Wednesday, 11 January 2012 10:26:32 UTC, callum wrote:
>
> I created an "Article" model with a few simple properties. I ran 
> syncdb, and set up the Django admin site, and added 
> "admin.site.register(Article)" in admin.py. Using the Django admin 
> site, I created an article by filling in the form. 
>
> I then went into models.py and added another property. I ran syncdb 
> again, ran the server again, then when I opened the Django admin site 
> again, I got the "no such column" error. 
>
> When I Googled this, the only obvious solutions I found were to reset 
> the app, or at least drop the database table that changed, and start 
> over. 
>
> But how do I do this without losing my data?


I can't believe your Googling didn't reveal the canonical solution:
http://south.aeracode.org/
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/jC-y1rKnyLUJ.
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 avoid "no such column" error when I add a new property to a model?

2012-01-11 Thread callum
I created an "Article" model with a few simple properties. I ran
syncdb, and set up the Django admin site, and added
"admin.site.register(Article)" in admin.py. Using the Django admin
site, I created an article by filling in the form.

I then went into models.py and added another property. I ran syncdb
again, ran the server again, then when I opened the Django admin site
again, I got the "no such column" error.

When I Googled this, the only obvious solutions I found were to reset
the app, or at least drop the database table that changed, and start
over.

But how do I do this without losing my 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: Please help me with django form 2.

2012-01-11 Thread kenneth gonsalves
On Tue, 2012-01-10 at 23:49 -0800, coded kid wrote:
> names=models.CharField(max_length=50) etc. I hope you get my point?
> Please help. 

I would suggest that you get to a computer and post the full code.
Please help us to help you.
-- 
regards
Kenneth Gonsalves

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