Re: Django form(s) for intermediary models

2011-01-26 Thread aa56280
Wow, that is bananas, Ian. I'll give your solution a try and see what
happens.

-- 
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 form(s) for intermediary models

2011-01-25 Thread aa56280
> In your case it would become something like:
>
> class Membership(ModelForm):
>         class Meta:
>                 model = Membership
>                 fields = ('person', 'date_joined')
>                 widgets = {
>                         'person' : CheckBox(),
>                         'date_joined': TextInput(),
>                 }

I need a form for each person though because a Group could have many
members.

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



Django form(s) for intermediary models

2011-01-25 Thread aa56280
I have three models like so:

class Person(models.Model):
  name = models.CharField(max_length=128)

class Group(models.Model):
  name = models.CharField(max_length=128)
  members = models.ManyToManyField(Person, through='Membership')

class Membership(models.Model):
  person = models.ForeignKey(Person)
  group = models.ForeignKey(Group)
  date_joined = models.DateField()

I already have the Person and Group tables populated. I'm now trying
to add members to each Group and would like to create a form that
gives me the option to create a Membership as well. In that form, I'd
like to see a checkbox for each Person (member) and a text field for
'date_joined'. Anyway to do this?

Any help would be greatly 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: URLField strange error

2011-01-19 Thread aa56280
Something's not right with the data. Can you post more details - like, what 
string are you trying to insert exactly?

-- 
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: Suppressing field in template for ChoiceField with only one option.

2010-09-29 Thread aa56280
Can't you specify the value using the initial argument?
http://docs.djangoproject.com/en/dev/ref/forms/fields/#initial


On Sep 29, 3:33 pm, Shawn Milochik  wrote:
> Actually, I spoke too soon on this one. My original solution doesn't work 
> because the hidden input on the form doesn't have a value, so the form won't 
> validate.
>
> I fixed this by just adding display: none to the widget attrs in the __init__ 
> instead of changing the widget to a HiddenInput. Now the "initial" value I 
> set in __init__ comes back through when the form is submitted.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Checkbox registration from

2010-09-29 Thread aa56280
You'll have to use the RegistrationFormTermsOfService class instead of
RegistrationForm.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Suppressing field in template for ChoiceField with only one option.

2010-09-29 Thread aa56280
That seems pretty straightforward me. You want to customize the form
based on the user and so you're doing it when the form is initialized.
Makes perfect sense.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Something breaking if tag

2010-09-29 Thread aa56280
Thanks for that. I figured it was something along those lines. I
didn't think Django did a check on the type as well when evaluating
the expression, but apparently it does. Very interesting.

Thanks again.



On Sep 29, 2:46 pm, Yo-Yo Ma <baxterstock...@gmail.com> wrote:
> request.GET.get('subtopic') is returning a string, so your if
> statement is roughly equivalent to:
>
> >>> 1 == '1'
>
> False
>
> The sub_topic = int(request.GET.get('subtopic')) is the correct way to
> do that. At first glance it seems like a lot of work, but if Django
> tried to deserialize URL params automatically into Python objects
> (like int), you would have all sorts of issues (like a "username"
> being passed in as an int because a user decides to make their name
> "1234", and so on).
>
> On Sep 29, 12:52 pm, aa56280 <aa56...@gmail.com> wrote:
>
> > I have in my template the following:
>
> > {% if subtopic.id == selected_id %}...{% endif %}
>
> > subtopic.id is being pulled from a list of subtopics that I'm looping
> > over.
>
> > selected_id is being sent to the template by the view after some form
> > processing:
> > #views.py
> > selected_id = request.GET.get('subtopic', '')
> > ...
>
> > For some reason, my {% if %} statement in the template isn't getting
> > evaluated even when the values of both subtopic.id and selected_id are
> > the same. It does, however, work properly if I do the following before
> > I send selected_id to the template:
> > #views.py
> > selected_id = int(selected_id)
>
> > Why is this? I'm wondering.
>
> > Thanks in advance for any insight.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: LOGIN FORM

2010-09-29 Thread aa56280
Do you have 'django.middleware.csrf.CsrfViewMiddleware' specified in
your settings?


On Sep 28, 2:55 pm, Saad Sharif  wrote:
> Hi all,
>            I want to create  a simple login form in django..Please
> help I am a complete beginner
>
> My Code:
>  dojoType="dijit.form.Form" >{% csrf_token %}
> username 
> password 
>  login 
> 
>
> Error Message (when I press login button) :
>
> Forbidden (403)
>
> CSRF verification failed. Request aborted.
> Help
>
> Reason given for failure: CSRF token missing or incorrect.
>
> In general, this can occur when there is a genuine Cross Site Request
> Forgery, or when Django's CSRF mechanism has not been used correctly.
> For POST forms, you need to ensure:
>
>     * The view function uses RequestContext for the template, instead
> of Context.
>     * In the template, there is a {% csrf_token %} template tag inside
> each POST form that targets an internal URL.
>     * If you are not using CsrfViewMiddleware, then you must use
> csrf_protect on any views that use the csrf_token template tag, as
> well as those that accept the POST data.
>
> You're seeing the help section of this page because you have DEBUG =
> True in your Django settings file. Change that to False, and only the
> initial error message will be displayed.
>
> You can customize this page using the CSRF_FAILURE_VIEW setting."
>
> Please 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-us...@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.



Something breaking if tag

2010-09-29 Thread aa56280
I have in my template the following:

{% if subtopic.id == selected_id %}...{% endif %}

subtopic.id is being pulled from a list of subtopics that I'm looping
over.

selected_id is being sent to the template by the view after some form
processing:
#views.py
selected_id = request.GET.get('subtopic', '')
...

For some reason, my {% if %} statement in the template isn't getting
evaluated even when the values of both subtopic.id and selected_id are
the same. It does, however, work properly if I do the following before
I send selected_id to the template:
#views.py
selected_id = int(selected_id)

Why is this? I'm wondering.

Thanks in advance for any insight.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Updating user's unique e-mail

2010-08-19 Thread aa56280
> Is best practice to do this from a custom user profile? I have an
> avatar imageField which will be editable as well.

Well, the first name, last name and e-mail fields are part of the User
model so you wouldn't need a profile model for that. As for the
avatar, yes, that would have to go in that profile model.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Encoding with {% url %} tag

2010-08-16 Thread aa56280
> In other words, if you designed the URL regex to handle a certain sort
> of string, and the view it points to handle a certain sort of string,
> and now in your template you're running that string through iriencode
> first, then the URL definition and the view it points to is receiving
> something other than what it was meant to receive.

Even if my regex is wrong, that doesn't mean the iriencode filter
wouldn't work - and that's really the crux of the matter here. I'm
applying the filter and string remains unchanged in the URL.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Encoding with {% url %} tag

2010-08-15 Thread aa56280
> Does the view code in app.views.blah know what to do with the
> iriencode'd values?

What does that have to do with anything? Don't get me wrong, I'll
figure that out eventually, but at the moment, I'm merely interested
in encoding the URL first - which isn't happening.

> Remember there are two ways to generate URLs in your templates -
> either with the {% url ... %} tag as you're doing now or with a
> get_absolute_url() method on the model (you then refer to  href="{{ instancename.get_absolute_url }}"> in your template).

I'll look into that. But I would really like to see if I can get this
to work. Seems like it should.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Encoding with {% url %} tag

2010-08-12 Thread aa56280
I'm using the url tag like so: {% url app.views.blah var1, var2 %}

var1 and var2 need to be encoded, using the iriencode filter, so I
tried this: {% url app.views.blah var1|iriencode, var2|iriencode %}

That doesn't do anything though. I can't find any examples anywhere to
figure this out.  Any thoughts?

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-us...@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 sessions issue

2010-06-07 Thread aa56280
> You better show some code now...

My urls.py has the following entry:
(r'^accounts/logout/$', 'django.contrib.auth.views.logout',
{'next_page' : '/'})

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 sessions issue

2010-06-04 Thread aa56280
> How are you logging out? Are you sure you are calling
> django.contrib.auth.logout() ?

Yup, I'm calling django.contrib.auth.views.logout()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 sessions issue

2010-06-03 Thread aa56280
Django's docs say: "When a user logs in, Django adds a row to the
django_session database table. Django updates this row each time the
session data changes. If the user logs out manually, Django deletes
the row. But if the user does not log out, the row never gets
deleted."

I'm logging out of my app but I notice that the row DOES NOT get
deleted. Is there something I'm missing here?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Separate views for form display and handling

2009-12-10 Thread aa56280
> render_to_response('foo.html', {'form' : form'})

Forgot to add: the form instance in this case will be bound to the
submitted data and will contain the appropriate errors.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Separate views for form display and handling

2009-12-10 Thread aa56280
First of all, any reason why you're using different views and not the
same view?

Second, yes it's possible to do what you're trying to do. Try this:

if form.is_valid():
  # do something and redirect
else:
  render_to_response('foo.html', {'form' : form'})

--

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




Re: django-registration terms of service link

2009-12-04 Thread aa56280
The "safe" filter works on a string, not the entire form. So you'll
have to apply it to the label of the field:

{{ form.tos.label|safe }}

Hope that helps.



On Dec 4, 11:55 am, Viktor  wrote:
> ahoj,
>
> I wrote a simple backend that extends RegistrationFormTermsOfService
> of django-restration as I would like to add links into the text
> stating that the user accepts the terms of service.
>
> But when I pass it to the template, the link's text is always escaped.
> I've tried to add a template filter, but it didn't help.
>
> here is the code
>
> class RegistrationFormTermsOfService(RegistrationForm):
>     tos = forms.BooleanField(widget=forms.CheckboxInput
> (attrs=attrs_dict),
>                              label=_(u'I have read and agree to the  href="%s">Terms of Service') % settings.TERMS_OF_SERVICE_URL,
>                              error_messages={ 'required': _("You must
> agree to the terms to register") })
>
> and I've tried to write this out with:
> {{ form|safe }}
>
> but I still ended up with:
> I have read and agree to the Terms of Service:
>
> could someone give me an idea how to solve this problem?
>
> thx, Viktor

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Show additional user information in admin

2009-12-03 Thread aa56280
> That works, but it would be nice to see and edit the
> entrys in UserProfile directly via admin/auth/user. From my novice
> standpoint, it looks like i have to overwrite the default admin.py
> from the auth module. Is that right? And if yes, how do I do it "the
> right way"?

You can do that by creating an InlineModelAdmin:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 Friendship relationship question.

2009-12-02 Thread aa56280
Couple things:

1) Your query is not working because if user1 added user2, then you
should be looking at from_friend not to_friend.

2) You haven't posted the code where you're creating friendships but
I'm assuming you are not creating symmetrical friendships there. That
is, if user1 adds user2, you create a record in the table and you move
on, but you need to create another record to symbolize the friendship
the other way around. Have a look at symmetrical ManyToMany
relationships and see if it's possible to go that route - it actually
uses a friends example :-)
http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyField.symmetrical

Hope that helps.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Caught an exception while rendering: Reverse for 'portal.compliance_index' with arguments '()' and keyword arguments '{}' not found.

2009-12-02 Thread aa56280
Does your urls.py contain an entry for compliance_index?

On Dec 2, 2:05 pm, Saravanan  wrote:
> Environment:
>
> Request Method: GET
> Request URL:http://shellwing251.atdesk.com/
> Django Version: 1.0.2 final
> Python Version: 2.4.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.admin',
>  'portal.utils',
>  'portal.corp_act']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'portal.utils.auth.ATDUserAuthMiddleware')
>
> Template error:
> In template /home/skannan/borgTraining/atd/borg/portal/templates/
> index.html, error at line 10
>    Caught an exception while rendering: Reverse for
> 'portal.compliance_index' with arguments '()' and keyword arguments
> '{}' not found.
>    1 : {% extends "base.html" %}
>
>    2 :
>
>    3 : {% block breadcrumbs %}Home{% endblock %}
>
>    4 : {% block pageheading %}Borg Control for {{ SITE_LONG_NAME }}{%
> endblock %}
>
>    5 :
>
>    6 : {% block content %}
>
>    7 : 
>
>    8 :   Customer/Conduit li>
>
>    9 :   Corporate Actions li>
>
>    10 :   Compliance li>
>
>    11 : 
>
>    12 : {% endblock %}
>
>    13 :
>
> Traceback:
> File "/usr/lib64/python2.4/site-packages/django/core/handlers/base.py"
> in get_response
>   86.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "/usr/lib64/python2.4/site-packages/django/views/generic/
> simple.py" in direct_to_template
>   18.     return HttpResponse(t.render(c), mimetype=mimetype)
> File "/usr/lib64/python2.4/site-packages/django/template/__init__.py"
> in render
>   176.         return self.nodelist.render(context)
> File "/usr/lib64/python2.4/site-packages/django/template/__init__.py"
> in render
>   768.                 bits.append(self.render_node(node, context))
> File "/usr/lib64/python2.4/site-packages/django/template/debug.py" in
> render_node
>   71.             result = node.render(context)
> File "/usr/lib64/python2.4/site-packages/django/template/
> loader_tags.py" in render
>   97.         return compiled_parent.render(context)
> File "/usr/lib64/python2.4/site-packages/django/template/__init__.py"
> in render
>   176.         return self.nodelist.render(context)
> File "/usr/lib64/python2.4/site-packages/django/template/__init__.py"
> in render
>   768.                 bits.append(self.render_node(node, context))
> File "/usr/lib64/python2.4/site-packages/django/template/debug.py" in
> render_node
>   71.             result = node.render(context)
> File "/usr/lib64/python2.4/site-packages/django/template/
> loader_tags.py" in render
>   24.         result = self.nodelist.render(context)
> File "/usr/lib64/python2.4/site-packages/django/template/__init__.py"
> in render
>   768.                 bits.append(self.render_node(node, context))
> File "/usr/lib64/python2.4/site-packages/django/template/debug.py" in
> render_node
>   81.             raise wrapped
>
> Exception Type: TemplateSyntaxError at /
> Exception Value: Caught an exception while rendering: Reverse for
> 'portal.compliance_index' with arguments '()' and keyword arguments
> '{}' not found.
>
> Original Traceback (most recent call last):
>   File "/usr/lib64/python2.4/site-packages/django/template/debug.py",
> line 71, in render_node
>     result = node.render(context)
>   File "/usr/lib64/python2.4/site-packages/django/template/
> defaulttags.py", line 378, in render
>     args=args, kwargs=kwargs)
>   File "/usr/lib64/python2.4/site-packages/django/core/
> urlresolvers.py", line 253, in reverse
>     return iri_to_uri(u'%s%s' % (prefix, get_resolver(urlconf).reverse
> (viewname,
>   File "/usr/lib64/python2.4/site-packages/django/core/
> urlresolvers.py", line 242, in reverse
>     raise NoReverseMatch("Reverse for '%s' with arguments '%s' and
> keyword "
> NoReverseMatch: Reverse for 'portal.compliance_index' with arguments
> '()' and keyword arguments '{}' not found.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Show additional user information in admin

2009-12-02 Thread aa56280
You'll have to "activate" the model like any other in order for it to
show up on the Admin site.

Have a look here: 
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overview


On Dec 2, 3:32 pm, Kai Timmer  wrote:
> Hello,
> by following this 
> guide:http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-...
> I made a model and added some information to every user. What do I
> have to do, to show these additional fields in the admin/user
> interface?
>
> Greetings,
> --
> Kai Timmer |http://kaitimmer.de
> Email : em...@kaitimmer.de
> Jabber (Google Talk): k...@kait.de

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Application not showing in admin panel

2009-12-02 Thread aa56280
On Dec 2, 2:17 pm, "dr.NO"  wrote:
> I've installed application djangodblog, it's working, it's logging
> everything into db - but it's not showing in the admin panel ... - any
> idea how to fix thax ?

Did you follow the steps outlined in the doc?
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overview

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: missing template for login page

2009-12-02 Thread aa56280
> I tried copying /django/contrib/auth/tests/templates/ to
> /django/contrib/auth/ but this gives me a form with only two fields and
>   no submit button ...

The form you are getting sounds like the right one.

You'll get a username field and a password field, but you'll have to
provide your own  tag and submit button.

Have a look at the sample login template:
http://docs.djangoproject.com/en/dev//topics/auth/#django.contrib.auth.views.login


--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Forms ModelMultipleChoiceField with checkboxes?

2009-11-23 Thread aa56280
leoz01, Django comes with a widget for precisely this use case (check
link above). Creating your own would be a complete waste of time.

On Nov 20, 3:52 am, leoz01  wrote:
> I think the easiest way is to make your own widget or otherwise you
> can make your own form field.
>
> On 19 nov, 10:19, Benjamin Wolf  wrote:
>
> > Hello,
>
> > I'm using Django's form and ModelMultipleChoiceField.
> > ModelMultipleChoiceField produces a select list with multiple options.
> > Is it possible to use
> >checkboxesinstead?
>
> > Thanks,
> > Greets Ben

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Forms ModelMultipleChoiceField with checkboxes?

2009-11-21 Thread aa56280
Yes, have a look at this: 
http://docs.djangoproject.com/en/dev/ref/forms/widgets/#specifying-widgets

The widget class for Checkboxes would be django.forms.widgets import
CheckboxSelectMultiple

Hope that helps.

On Nov 19, 3:19 am, Benjamin Wolf  wrote:
> Hello,
>
> I'm using Django's form and ModelMultipleChoiceField.
> ModelMultipleChoiceField produces a select list with multiple options.
> Is it possible to use
> checkboxes instead?
>
> Thanks,
> Greets Ben

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Re: Customizing error message for unique ModelForm field

2009-11-05 Thread aa56280

Also, I'd like to customize the error returned when someone tries to
save the slug with invalid characters, such as spaces. That one
currently says "Enter a valid 'slug' consisting of letters, numbers,
underscores or hyphens." The terms slug doesn't make sense to some of
my users.

On Nov 5, 4:38 pm, aa56280 <aa56...@gmail.com> wrote:
> I have a ModelForm with a slug field with unique=True. I need to make
> the error message a bit more "friendly." Is there a way to override
> the default error message? The default is: "[model_name] with this
> [field_label] already exists."
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Customizing error message for unique ModelForm field

2009-11-05 Thread aa56280

I have a ModelForm with a slug field with unique=True. I need to make
the error message a bit more "friendly." Is there a way to override
the default error message? The default is: "[model_name] with this
[field_label] already exists."
--~--~-~--~~~---~--~~
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 manage (for testserver) fixtures files when use django.contrib.auth

2009-10-15 Thread aa56280

Are you looking for help on creating fixtures? If so, try this:
http://docs.djangoproject.com/en/dev/howto/initial-data/#howto-initial-data

If you're trying to add users using fixtures, then have a look here:
http://groups.google.com/group/django-users/browse_thread/thread/c66f564797e64d47/35ab82234e8fe7c7?q=#35ab82234e8fe7c7


On Oct 15, 12:18 pm, Jacobian  wrote:
> I find very much, if exists a link with explain could you send me,
> Thanks.
>
> P.D. Sorry, for my english.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Customizing form widget

2009-10-15 Thread aa56280

I have a Category and SubCategory model. Each SubCategory belongs to a
Category via a Foreign Key. (So each Category can have many
SubCategories.)

I have several places throughout my app where I show the list of
SubCategories as part of some ModelForm. It renders like so:


subcategory 1
subcategory 2
subcategory 3
...



Which is dandy, but I would like to customize this a bit by showing
Categories as well in an , like so:



  subcategory 1
  subcategory 2
  subcategory 3

...


Any ideas on how I can make that happen? Thanks in advance for any
help.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Querying for objects created on a certain date

2009-10-12 Thread aa56280

Karen,

I'm aware that my 30-days-ago version of the query is current time/
date specific. Good catch :-)

Thanks for the solution. I also found this one:
today = datetime.datetime.today()
Document.objects.filter(created_on__month=today.month,
created_on__day=today.day, created_on__year=today.year)

Thanks again.


On Oct 12, 5:00 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Oct 12, 2009 at 5:07 PM, aa56280 <aa56...@gmail.com> wrote:
>
> > I have a DateTimeField called "created_on" on a model called
> > "Documents". It serves as a timestamp for when the record was added.
>
> > I'm trying to write a query that will return all Documents created_on
> > a particular date, say today. I can make it work if I look for a
> > record within a range of dates...
>
> > 
> > today = datetime.datetime.today()
> > thirty_days_ago = today - datetime.timedelta(days=30)
> > Document.objects.filter(created_on__range=(thirty_days_ago, today))
> > 
>
> > But now, I need to find records that were created on a particular
> > date, like, today.
>
> > How do I do that?
>
> today_end = datetime.datetime.combine(datetime.date.today(),
> datetime.time.max)
> today_start = datetime.datetime.combine(datetime.date.today(),
> datetime.time.min)
> Document.objects.filter(created_on__range=(today_start, today_end))
>
> You realize your 30-days-ago version of the query returns values that depend
> on the current time as well as the current date when the query is run? This
> may be rather surprising behavior for people who would likely expect the
> list of things created within the last 30 days to be constant over the
> course of a day (excepting things added during the day).
>
> Karen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Querying for objects created on a certain date

2009-10-12 Thread aa56280

I have a DateTimeField called "created_on" on a model called
"Documents". It serves as a timestamp for when the record was added.

I'm trying to write a query that will return all Documents created_on
a particular date, say today. I can make it work if I look for a
record within a range of dates...


today = datetime.datetime.today()
thirty_days_ago = today - datetime.timedelta(days=30)
Document.objects.filter(created_on__range=(thirty_days_ago, today))


But now, I need to find records that were created on a particular
date, like, today.

How do I do that?

Any thoughts greatly 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: send_mass_mail on object creation

2009-09-19 Thread aa56280

> The way I have handled this in the past is to create a simple app that you
> can run from the command line. I had it check a table that was updated with
> the list of emails to send and set it up as a scheduled task (cron job) for
> every 20 minutes or so.

I was leaning toward a similar solution. 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
-~--~~~~--~~--~--~---



send_mass_mail on object creation

2009-09-18 Thread aa56280

When a new instance of some object is created, I need to send out X
number of emails. X could potentially mean hundreds of emails.

What would be the most efficient way to do this?

I know if I use send_mass_mail() it could potentially hang for quite a
long time.

Any thoughts greatly 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: Imagefield, PIL and save()

2009-09-03 Thread aa56280

On Sep 3, 5:31 pm, Rob Broadhead  wrote:
> If you are on a Mac there are some issues with the imagelib you will  
> need to fix.

Very interesting. I am on a Mac. So I'll investigate and update.
Thanks, Rob.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Imagefield, PIL and save()

2009-09-03 Thread aa56280

I have an ImageField in a model. I also have a ModelForm for this
model. I'm overriding save() so that I can take the image that was
uploaded and make a thumbnail out of it using PIL.

I'm using the simplest of examples just to get started:

...
def save(self):
  from PIL import Image

  im = Image.open(self.logo)  # 'logo' is the image field name
  im.thumbnail((100,100), Image.ANTIALIAS)
  im.save('test.png')

No exception, no errors, but neither was a thumbnail created. I keep
thinking something's going on with the Image.open() method, but I have
no clue what. Any ideas greatly 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: unique=True and IntegrityError

2009-09-01 Thread aa56280

> The check for unique fields is done in the base ModelForm clean method.  By
> overriding clean without calling the superclass clean you are causing the
> checks to be bypassed.

I read up on it while you were posting your reply :)

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-clean-method

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



Re: unique=True and IntegrityError

2009-09-01 Thread aa56280

You're right, I did leave out something - the clean() method. Nothing
unusual there. In fact, if I take out everything from the method and
leave the shell:

def clean(self):
  return self.cleaned_data

It still craps out. However, if I take away the entire method, then I
do get the validation error.
--~--~-~--~~~---~--~~
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: unique=True and IntegrityError

2009-08-31 Thread aa56280

On Aug 31, 9:51 pm, Karen Tracey  wrote:

> However if you use a ModelForm to validate the data prior to attempting to
> save the model you get these problems reported as validation errors:

Karen,

Thanks for the thorough explanation. I really appreciate it. What I
took from it is that if I'm using a ModelForm, Django should return a
validation error for a duplicate value. However, for my scenario, I
*am* using a ModelForm. Here's a snippet:

### Model ###
class School(models.Model):
url = models.SlugField(max_length=50, unique=True)
name = models.CharField(max_length=255)
...


### Form ###
class SchoolForm(ModelForm):

class Meta:
model = School
fields = ('url', 'name')

### View ###
def new_school(request):
if request.method == 'POST':
form = SchoolForm(request.POST)
if form.is_valid():
form.save()

new_school craps out with an IntegrityError exception any time I have
a duplicate value. Any additional thoughts?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



unique=True and IntegrityError

2009-08-31 Thread aa56280

I can't find an answer to this, so I'm hoping folks here can help: why
is it that Django catches IntegrityError for a field with unique=True
in the Admin tool but requires you to catch it yourself in your app?
That is, why isn't it handled like all other built-in validation
checks that come bundled with other options like, say, max_length?

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



Class Meta discovery

2009-08-16 Thread aa56280

Not sure how well known this is but I thought I'd share seeing as how
it cost me a lot of time and I can't find any discussion of it:

I have a form for a model. The model has three fields, but I only want
one displayed in the form. So I do this:

class NoteForm(ModelForm):

class Meta:
model = Note
fields = ('text')

Looks good, but craps out with: 'Caught an exception while rendering:
'NoneType' object has no attribute 'label''.

I checked the ModelForms documentation and they have this example when
discussing field exclusion:

class PartialAuthorForm(ModelForm):
class Meta:
model = Author
exclude = ('birth_date',)

Notice the comma after 'birth_date'? That was it. Hope this helps
someone.
--~--~-~--~~~---~--~~
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: Creating users in fixtures

2009-06-30 Thread aa56280

Worked like a charm.

Thanks, Alex.

On Jun 30, 6:36 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Tue, Jun 30, 2009 at 6:32 PM, aa56280 <aa56...@gmail.com> wrote:
>
> > I'm trying to create a bunch of users in a initial_data.yaml fixture
> > file. What should I be using for the Model?
> > django.contrib.auth.user does not seem to be working. Django throws a
> > DeserializationError: Invalid model identifier:
> > 'django.contrib.auth.user'
>
> > Any help would be greatly appreciated.
>
> It's just auth.user.  You only use the app name (last part of the python
> path) and the model name.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Creating users in fixtures

2009-06-30 Thread aa56280

I'm trying to create a bunch of users in a initial_data.yaml fixture
file. What should I be using for the Model?
django.contrib.auth.user does not seem to be working. Django throws a
DeserializationError: Invalid model identifier:
'django.contrib.auth.user'

Any help would be greatly 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: ForeignKey with null=True

2009-05-15 Thread aa56280

Thanks for the quick turnaround Alex.

The reason why I'm going the location_set route is because I want to
make that the Location object has a relationship with the Company
object. Simply because both of these parameters are being provided the
user. (something that I left out in the code sample)



On May 15, 12:13 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Fri, May 15, 2009 at 12:11 PM, aa56280 <aa56...@gmail.com> wrote:
>
> > So to be clear then, yes, I want to delete the object from the
> > database entirely. How to go about doing that using location_set?
>
> > On May 15, 12:07 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> > > On Fri, May 15, 2009 at 12:04 PM, aa56280 <aa56...@gmail.com> wrote:
>
> > > > I'm trying to wrap my head around why a ForeignKey needs to be set
> > > > with null=True in order for its related model to call remove() on one
> > > > of its instances.
>
> > > > For example:
>
> > > > # models
> > > > class Company(models.Model):
> > > >    ...
> > > > class Location(models.Model):
> > > >    ...
> > > >    company= models.ForeignKey(Company)
>
> > > > # view
> > > > company = Company.objects.get(pk=1)
> > > > location = Location.objects.get(pk=1)
> > > > company.location_set.remove(location)  # raises 'RelatedManager'
> > > > object has no attribute 'remove'
>
> > > > Any help is appreciated as I can't find much documentation on this.
>
> > > Because the way to remove an object from a related set is to set the
> > foreign
> > > key to None, so it no longer refers to it, however if the foreign key
> > isn't
> > > nullable the only option is to actually delete the object, which isn't
> > > exactly the same as what you specifified (since its destructive).
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> You wouldn't do it using location_set, you could just do obj.delete() to
> delete it, then it will no longer be in location_set, since it doesn't exist
> in the DB at all :)
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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: ForeignKey with null=True

2009-05-15 Thread aa56280

So to be clear then, yes, I want to delete the object from the
database entirely. How to go about doing that using location_set?

On May 15, 12:07 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Fri, May 15, 2009 at 12:04 PM, aa56280 <aa56...@gmail.com> wrote:
>
> > I'm trying to wrap my head around why a ForeignKey needs to be set
> > with null=True in order for its related model to call remove() on one
> > of its instances.
>
> > For example:
>
> > # models
> > class Company(models.Model):
> >    ...
> > class Location(models.Model):
> >    ...
> >    company= models.ForeignKey(Company)
>
> > # view
> > company = Company.objects.get(pk=1)
> > location = Location.objects.get(pk=1)
> > company.location_set.remove(location)  # raises 'RelatedManager'
> > object has no attribute 'remove'
>
> > Any help is appreciated as I can't find much documentation on this.
>
> Because the way to remove an object from a related set is to set the foreign
> key to None, so it no longer refers to it, however if the foreign key isn't
> nullable the only option is to actually delete the object, which isn't
> exactly the same as what you specifified (since its destructive).
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ForeignKey with null=True

2009-05-15 Thread aa56280

I'm trying to wrap my head around why a ForeignKey needs to be set
with null=True in order for its related model to call remove() on one
of its instances.

For example:

# models
class Company(models.Model):
...
class Location(models.Model):
...
company= models.ForeignKey(Company)


# view
company = Company.objects.get(pk=1)
location = Location.objects.get(pk=1)
company.location_set.remove(location)  # raises 'RelatedManager'
object has no attribute 'remove'

Any help is appreciated as I can't find much documentation on this.



--~--~-~--~~~---~--~~
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: login decorator losing POST data

2009-05-14 Thread aa56280

Tim,

Thanks for the fantastic insight into the browser issues with 307
redirects. I'll explore this a bit further and see which route I want
to take.

Given that the form in question is simply a button that says "Join
network," I may be inclined to just let the user login, come back to
the page and submit the form again. An annoying experience (IMHO), but
one that eliminates all this hassle.

Thanks again.

--~--~-~--~~~---~--~~
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: login decorator losing POST data

2009-05-14 Thread aa56280

On May 14, 8:29 am, TiNo  wrote:

> Isn't it possible to force the user to login before filling out the form?
> That eliminates all the issues with redirecting the POST data.

How ironic. I clicked on the Reply link and Google told me I need to
sign in in order to reply. I was then brought back and had to click
Reply again.

So to answer your question TiNo, yes I could but the page I'm building
is very similar to this Google Groups page. It can be viewed by
anyone, but in order to perform certain actions, one needs to be
logged in.

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



login decorator losing POST data

2009-05-13 Thread aa56280

Hello there,

I have a form. Once it's submitted (method=POST) the view handling the
submit uses the @login_required decorator.

Problem is that when the login page intercepts to enforce login, it
passes the user over to the view via the "next" parameter but that's
no longer considered a POST request.

So how do I make sure that it remains a POST and not a GET?

Any help is appreciated. 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
-~--~~~~--~~--~--~---