Re: Any django reusable app for outdoor & indoor location, GPS tracking?

2017-09-27 Thread Lee Hinde
Regarding developing over https….

https://ngrok.com/ 

is a great tool when you want to use https locally.


> On Sep 27, 2017, at 12:35 PM, Jani Tiainen  wrote:
> 
> Hi.
> 
> To my knowledge there isn't one since we implemented our own tracker.
> 
> If you're going to build one I do have few pointers that you should consider.
> 
> Recent browser changes requires that location data is transferred over https. 
> I think chrome was first one to require it. That makes developing it a bit 
> challenging.
> 
> Raw coordinate data isn't that good since there is constant deviation in 
> coordinates. You'll need to pick some smoothing algorithm. Don't remember top 
> if my head what we use but I can check that when I go to work.
> 
> And then you need to have a background map. And that's the tricky part...
> 
> 26.9.2017 13.14 "'Federico Capoano' via Django users" 
> mailto:django-users@googlegroups.com>> 
> kirjoitti:
> Hi everyone,
> 
> before building my own reusable app all over again, I wanted to ask here if 
> there is any reusable django app that does indoor location and or GPS 
> tracking.
> I'm not looking for something full featured, but rather a starting point to 
> which I can contribute to.
> 
> Best regards
> Federico Capoano
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0667A36B-BA19-4302-A1EA-93AEB35E4F62%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to use input text placeholder when using {{ form.as_p }}

2017-07-26 Thread Lee Hinde
in the init method of your form do something like this:

self.fields['verification_date'].widget.attrs["placeholder"] = 'date'

> On Jul 26, 2017, at 1:31 PM, Alexander Joseph  
> wrote:
> 
> I'm using {{ form.as_p }} in my template and would like to be able to use 
> placeholders in the individual input fields. Is there a way to do this? Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24FEB5E0-92C9-4824-9BDD-82047D6D0AD9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with migrations cleaning up a date field

2017-06-12 Thread Lee Hinde
On Sat, Jun 10, 2017 at 5:03 AM, Melvyn Sopacua 
wrote:

> On Friday 09 June 2017 20:56:46 James Schneider wrote:
>
>
>
> > Quite honestly this sounds like a bug in the migration system if
>
> > that's the case. I'm pretty sure it should ask what value to use as a
>
> > filler value during the migration, although I haven't had a change
>
> > like that in a while.
>
>
>
> When you *remove* a default, there is no need to migrate existing rows, as
> they have a default.
>
>

I should have mentioned that I checked for empty date fields first and they
were all populated.

My work around was to skip the migration. Just redid the dependency on the
next migration and all was well.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMyD3_5o6p%2BwfJO%3DVa2L%2B__9vEQx6E-jg2BmCyGrawFQew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with migrations cleaning up a date field

2017-06-09 Thread Lee Hinde
I should add, this project is in 1.8.x. I'm working around the problem by
skipping the migration.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMxnZ_LHcKx-2R_fX7WUwo-qkhxTDZdBcO39zX%3DH2xBBBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problems with migrations cleaning up a date field

2017-06-09 Thread Lee Hinde
I'm having problems with a migration after cleaning up an oddity with a
date field and I'm not sure how to fix it.  Any advice appreciated.

I made this change to a date field:

-start_date = models.DateField(db_index=True, default=False,
-  help_text="The date enrollment can begin
this Season.")
+start_date = models.DateField(db_index=True, help_text="The date
enrollment can begin this Season.")

I'm not sure how a default of False ever made it, but I ran across it and
fixed it.

This is the migration that was created:

class Migration(migrations.Migration):

dependencies = [
('district', '0012_auto_20160622_1741'),
]

operations = [
migrations.AlterField(
model_name='season',
name='start_date',
field=models.DateField(help_text=b'The date enrollment can
begin this Season.', db_index=True),
),
]

This is the error I get trying to run the migration:

  Applying district.0013_auto_20170204_1811...Traceback (most recent call
last):
  File "manage.py", line 9, in 
execute_from_command_line(sys.argv)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/__init__.py",
line 354, in execute_from_command_line
utility.execute()
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/__init__.py",
line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/base.py",
line 394, in run_from_argv
self.execute(*args, **cmd_options)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/base.py",
line 445, in execute
output = self.handle(*args, **options)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
line 222, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/migrations/executor.py",
line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake,
fake_initial=fake_initial)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/migrations/executor.py",
line 148, in apply_migration
state = migration.apply(state, schema_editor)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/migrations/migration.py",
line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/migrations/operations/fields.py",
line 201, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/backends/base/schema.py",
line 484, in alter_field
old_db_params, new_db_params, strict)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/backends/base/schema.py",
line 566, in _alter_field
old_default = self.effective_default(old_field)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/backends/base/schema.py",
line 211, in effective_default
default = field.get_db_prep_save(default, self.connection)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
line 710, in get_db_prep_save
prepared=False)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
line 1322, in get_db_prep_value
value = self.get_prep_value(value)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
line 1317, in get_prep_value
return self.to_python(value)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
line 1274, in to_python
parsed = parse_date(value)
  File
"/Users/leehinde/Documents/Clients/rnrvirtual/venv-python2.7-django/lib/python2.7/site-packages/django/utils/dateparse.py",
line 60, in parse_date
match = date_re.match(value)
TypeError: expected string or buffer

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails fro

Shout out to Grove Collaborative for django-sql-explorer

2016-09-03 Thread Lee Hinde
Just did a quick report for a client with django-sql-explorer (
https://github.com/groveco/django-sql-explorer) and once again I'm grateful
for its existence.

Highly recommended for quick ad-hoc reporting.

(no relationship except that I'm a Grove Co customer so I can give back a
little bit.)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzqB6ace99Ut9fwzu%3DO7eu-pKa_RcsV%3DtjvO4-BYsBosg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Clarifying Project vs Apps

2016-08-24 Thread Lee Hinde
On Wed, Aug 24, 2016 at 9:23 AM, Rich Shepard 
wrote:

> On Wed, 24 Aug 2016, Lee Hinde wrote:
>
> My tuppence.
>>
>
> Lee,
>
>   Before or after Brexit? The value might change. :-)
>
> No, an app is a logical grouping of objects/tables. You might, for
>> instance,have an Invoice app that would include an Invoice table (model)
>> and a LineItems table. Products and related tables would be in a different
>> app.
>>
>
>   OK, that makes sense.
>
>   In my current project, then, all modules for company, contact, activity,
> case, etc. will be in a single app. And, perhaps, another app would be for
> reporting?
>
>   Translating from product-oriented applications to service-oriented ones
> is
> not always easy.
>
> Thanks very much,
>
> Rich
>
So, no one is going to grade it. You're making this for yourself, so I
wouldn't over think it. I'm working on a project now that only has two
apps, one with all the core models and one for utility models (like choice
lists).(I'm using several packages, so the database has more to it than
that.)

It sounds like something like that would work for you and still be 'right'.
Especially as a first time out of the gate project, keep it simple. IMHO.

While it will certainly evolve as you use it, you're not gong to suddenly
wake up and need 18 more apps to meet your needs. And if that does happen,
you can rearrange.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMwf38zOGytfpoQc49pdSuxLyw-zqEdaRcqcjhJE3dV4VA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Clarifying Project vs Apps

2016-08-24 Thread Lee Hinde

> On Aug 24, 2016, at 8:48 AM, Rich Shepard  wrote:
> 
>  While I think that I understand the differences between a project and its
> apps there remains one point of uncertainty. I've not found the answer,
> although it might be in the 1.10 docs or on the Web and I've missed it.
> 
>  If the project represents the entire database, do the apps represent
> individual tables? That is, should my project have a separate app for each
> table with its models, templates, and views with templates of joined tables
> in the main project subdirectory? Or are all tables in a single app?


My tuppence.. No, an app is a logical grouping of objects/tables. You might, 
for instance,have an Invoice app that would include an Invoice table (model) 
and a LineItems table. Products and related tables would be in a different app.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/A2166400-C5B5-4CCB-ABC2-0A5E1D92F6DF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Best way to keep the current selection

2016-07-26 Thread Lee Hinde
I'm wondering if there's a better way to maintain a selection of records
across calls to the app.

In one of my projects users can do ad-hoc searches; i.e., Last Name =
Smith, Class Name = Yoga, etc.

They do the search, then get the query results presented in a table.

Then they can do things with the selection like run reports or make it the
basis for further queries.

To maintain state, after any ad-hoc query, I store the ids for the found
records:

self.request.session['query.classes.last_ids'] =
list(queryset.values_list('id', flat=True))

It works fine and I've not had any problems I can lay to this. But I'm
executing the query at least twice and I'm storing, potentially, thousands
of ids in the session cache.

The only other alternative I've thought of was to store the query criteria
and re-execute it, but a) that's complicated and b) the underlying results
could change while the user is deciding on the next step.

Is there a best practice for this sort of thing?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMw6EOf%2B4%3DYPkutNeyqddYBGEPXjhg%2BeLr4eB2q7VBkihw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error uploading images

2016-07-02 Thread Lee Hinde
Aargh. Thanks.

On Saturday, July 2, 2016, Vijay Khemlani  wrote:

> The typical problem is forgetting to add the
>
> enctype='multipart/form-data'
>
> attribute to the form tag
>
>
>
> On Sat, Jul 2, 2016 at 9:40 PM, Lee Hinde  > wrote:
>
>> Using django-storages to put user uploaded files on s3.
>>
>> Uploading images in the shell works fine. So, I assume I've got
>> django-storages and boto installed fine and S3 configured correctly.
>>
>> Uploading in real-life, doesn't work. The error I get back is that the
>> image field is required.
>>
>> The model:
>>
>> class PropertyPhotos(models.Model):
>> property = models.ForeignKey(Property)
>> image = models.ImageField(upload_to="img")
>> title = models.CharField(max_length=200, blank=True)
>>
>> The form:
>>
>> class PhotoForm(forms.ModelForm):
>> property_key = forms.CharField(required=False,
>> widget=forms.HiddenInput())
>>
>> def __init__(self, property_key,  *args, **kwargs):
>> super(PhotoForm, self).__init__(*args, **kwargs)
>> self.initial['property_key'] = property_key
>>
>> class Meta:
>> model = PropertyPhotos
>> fields = [ 'image', 'title']
>> exclude = ['property', ]
>>
>>
>> The view:
>>
>> class AddPhotos(LoginRequiredMixin, CreateView):
>> form_class = PhotoForm
>> success_url = reverse_lazy('add_photos')
>> template_name = 'photo_entry.html'
>> model = PropertyPhotos
>>
>> def get_form_kwargs(self):
>> kwargs = super(AddPhotos, self).get_form_kwargs()
>> kwargs['property_key'] = self.kwargs.get('key')
>> return kwargs
>>
>> def form_valid(self, form):
>> photo = PhotoForm(self.request.POST, self.request.FILES)  #
>> form.save(commit=False)
>> url = form.cleaned_data['property_key']
>> photo.property = Property.objects.get(url_uuid=url)
>> photo.save()
>> return super(AddPhotos, self).form_valid(form)
>>
>> def get_context_data(self, **kwargs):
>> context = super(AddPhotos, self).get_context_data(**kwargs)
>> context['property_key'] = self.kwargs.get('key')
>> context['property_obj'] =
>> Property.objects.get(url_uuid=self.kwargs.get('key'))
>> return context
>>
>> The form part of the template (mostly to show that the image input is
>> within the form :
>>
>> 
>> {{ form.errors }}
>> {% csrf_token %}
>> {{ form.property_key }}
>> Add Photos for  - {{ property_obj.title }}
>> {{ form.as_p }}
>>
>> 
>> 
>> > value="Upload" id="submit" type="submit">
>> Upload
>> 
>> 
>>
>> 
>> 
>>
>> I'd appreciate a code review that will tell me which mis-placed
>> semi-colon is causing my errors.
>>
>> Thanks!
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMyipqzzD-yvA3k4JOn0YG4sDD20VYS2Jm9E509WFWOMXQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Error uploading images

2016-07-02 Thread Lee Hinde
Using django-storages to put user uploaded files on s3.

Uploading images in the shell works fine. So, I assume I've got
django-storages and boto installed fine and S3 configured correctly.

Uploading in real-life, doesn't work. The error I get back is that the
image field is required.

The model:

class PropertyPhotos(models.Model):
property = models.ForeignKey(Property)
image = models.ImageField(upload_to="img")
title = models.CharField(max_length=200, blank=True)

The form:

class PhotoForm(forms.ModelForm):
property_key = forms.CharField(required=False,
widget=forms.HiddenInput())

def __init__(self, property_key,  *args, **kwargs):
super(PhotoForm, self).__init__(*args, **kwargs)
self.initial['property_key'] = property_key

class Meta:
model = PropertyPhotos
fields = [ 'image', 'title']
exclude = ['property', ]


The view:

class AddPhotos(LoginRequiredMixin, CreateView):
form_class = PhotoForm
success_url = reverse_lazy('add_photos')
template_name = 'photo_entry.html'
model = PropertyPhotos

def get_form_kwargs(self):
kwargs = super(AddPhotos, self).get_form_kwargs()
kwargs['property_key'] = self.kwargs.get('key')
return kwargs

def form_valid(self, form):
photo = PhotoForm(self.request.POST, self.request.FILES)  #
form.save(commit=False)
url = form.cleaned_data['property_key']
photo.property = Property.objects.get(url_uuid=url)
photo.save()
return super(AddPhotos, self).form_valid(form)

def get_context_data(self, **kwargs):
context = super(AddPhotos, self).get_context_data(**kwargs)
context['property_key'] = self.kwargs.get('key')
context['property_obj'] =
Property.objects.get(url_uuid=self.kwargs.get('key'))
return context

The form part of the template (mostly to show that the image input is
within the form :


{{ form.errors }}
{% csrf_token %}
{{ form.property_key }}
Add Photos for  - {{ property_obj.title }}
{{ form.as_p }}




Upload






I'd appreciate a code review that will tell me which mis-placed semi-colon
is causing my errors.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMysqRa-Dqk8sUJ67mr4y2mQBbs2eDpqMVGN6NP9fj7f-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: LoginRequiredMixin ignored

2016-06-16 Thread Lee Hinde
I always assume it's me. That was some errant copy and paste.

Thanks!

On Wed, Jun 15, 2016 at 11:51 PM, Babatunde Akinyanmi 
wrote:

> Actually it's you. Please see inline:
>
> On Jun 15, 2016 11:56 PM, "Lee Hinde"  wrote:
> >
> > Using Django 1.9.7.
> >
> > I have the following class:
> >
> > class AddView(LoginRequiredMixin, CreateView):
> > template_name = "entry.html"
> > model = Property
> > form_class = AddPropertyForm
> > success_url = "/buy/"
> > login_url = '/account/login/'
> >
>
> Consider your code for `dispatch`
> > def dispatch(self, request, *args, **kwargs):
> > print request.user
> > print request.user.is_authenticated()
> > return super(AddView, self).post(request, *args, **kwargs)
> >
> You have bypassed `LoginRequiredMixin` implementation of `dispatch` and
> there's where the login logic is done. You should be returning a super call
> to `dispatch` not `post`. If you are actually trying to force all requests
> into POSTs (which I doubt), you are better off doing it in the `get`
> method.
>
> > def form_valid(self, form):
> > ls_property = form.save(commit=False)
> > ls_property.user = get_user(self.request)
> > ls_property.latitude = form.cleaned_data['latitude']
> > ls_property.longitude = form.cleaned_data['longitude']
> > submit =  form.cleaned_data['submit']
> > ls_property.visible = (submit != 'draft')
> > ls_property.save()
> > return super(AddView, self).form_valid(form)
> >
> >
> > The LoginRequiredMixin is ignored, i.e, I can get to the page without
> being logged in.
> >
> > request.user reports: AnonymousUser
> > request.user.is_authenticated() reports: False
> >
> > If I wrap the url:
> >
> > url(r'^sell', user_passes_test(user_is_active)(AddView.as_view()),
> name="add"),
> >
> > the page is protected, so I have a work around.
> >
> > This seems basic and I don't find other reports of LoginRequiredMixin
> not working, so I assume it's me.
> >
> > What am I missing?
> >
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMwMHRW6cEbzPypBhTnGCRJ7W0nGE%2BvaQ_ytmA_D2WhiSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


LoginRequiredMixin ignored

2016-06-15 Thread Lee Hinde
Using Django 1.9.7.

I have the following class:

class AddView(LoginRequiredMixin, CreateView):
template_name = "entry.html"
model = Property
form_class = AddPropertyForm
success_url = "/buy/"
login_url = '/account/login/'

def dispatch(self, request, *args, **kwargs):
print request.user
print request.user.is_authenticated()
return super(AddView, self).post(request, *args, **kwargs)

def form_valid(self, form):
ls_property = form.save(commit=False)
ls_property.user = get_user(self.request)
ls_property.latitude = form.cleaned_data['latitude']
ls_property.longitude = form.cleaned_data['longitude']
submit =  form.cleaned_data['submit']
ls_property.visible = (submit != 'draft')
ls_property.save()
return super(AddView, self).form_valid(form)


The LoginRequiredMixin is ignored, i.e, I can get to the page without
being logged in.

request.user reports: AnonymousUserrequest.user.is_authenticated()
reports: False

If I wrap the url:

url(r'^sell', user_passes_test(user_is_active)(AddView.as_view()), name="add"),

the page is protected, so I have a work around.

This seems basic and I don't find other reports of LoginRequiredMixin
not working, so I assume it's me.

What am I missing?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzApQGdzZ9AW47CjF3yhT0Smnc1AZw%2BOQ8uTcH1G3%3Dasg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Absolute beginner step by step

2016-06-11 Thread Lee Hinde
https://leanpub.com/tangowithdjango19/ 


> On Jun 11, 2016, at 2:07 PM, Gary Roach  wrote:
> 
> If you don't mind working with Python2.7 and Django 1.7 you might try "Tango 
> With Django" . It is out of date but still is a good place to start. Too bad 
> that the author hasn't updated it. I

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0FDE615E-8BF0-459C-9D3D-A45E3CD28CBF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django css: general query on CDNs and crispy forms

2016-02-23 Thread Lee Hinde
On Feb 23, 2016, at 5:27 PM, clarksonchri...@gmail.com wrote:
> 
> Should i download bootstrap properly or do the CDNs suffice?
Your call; but if you want to have a plan B, here’s an example:  
http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx
 


It’s about jQuery, but the same principal would apply for bootstrap.

> Where do I store the bootstrap code and how will it affect my own CSS code?
You put it the same place you’d have your other js/css files. Loading order 
matters. I usually load libraries first and then my files.

> How do register the module crispy_forms? and where do I store the crispy 
> forms folder there is little documentation on this?
Crispy Forms has documentation. 
http://django-crispy-forms.readthedocs.org/en/latest/ 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0AE63F7B-91B3-4A10-8C03-74DF56DB08D9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Could not parse the remainder template inheritance

2016-01-02 Thread Lee Hinde
If you’re just getting your feet wet and don’t want to invest in an editor/IDE 
just yet, try TextWrangler: http://www.barebones.com/products/textwrangler/ 
  It’s free and won’t get in 
your way.

> On Jan 2, 2016, at 8:11 AM, Matthew  wrote:
> 
> Actually it turned out this works!! My TextEdit app was being finnicky and 
> made me re-write the entire code instead of just the quotation marks. Thanks 
> for the help!
> 
> On Saturday, January 2, 2016 at 10:52:22 AM UTC-5, Matthew wrote:
> Hi James,
> 
> I turned smart quotes off and am still having the error.  I wasn't aware that 
> could cause future errors though, so thanks for the heads up!
> 
> On Saturday, January 2, 2016 at 12:44:22 AM UTC-5, James Schneider wrote:
> 
> On Jan 1, 2016 8:08 PM, "Matthew" > wrote:
> >
> > Hi all,
> >
> > I'm working through the masteringdjango book, and am struggling in the 
> > Templates area.
> >
> > I created a base.html base template, and am attempting to include a child 
> > template.
> >
> > This is the child template:
> >
> > {% extends “base.html” %}
> >
> > {% block title %}The current time{% endblock %}
> >
> > {% block content %}
> > It is now {{ current_date }}.
> > {% endblock %}
> >
> > When I run the site, I get the following error message: 
> > Could not parse the remainder: '“base.html”' from '“base.html”'
> >
> > And it points to the first line of the child template.
> >
> > I don't understand what I am doing wrong, please help.
> 
> Was this template code primarily copied/pasted from an example?
> 
> Can you try deleting and manually typing new quotes around the base.html 
> reference in your {% extends %} tag?
> 
> Not sure if it's my email client or not, but those appear to be "smart 
> quotes", which lean left/right, usually automatically inserted by editor 
> applications like MS Word or possible from a translation from text to PDF to 
> make things "pretty".
> 
> To a computer parser like the Django template system, those are interpreted 
> differently as regular characters rather than quotes, which would explain the 
> parser error you are receiving. Hard to spot, but I've been bit by that type 
> of subtle bug before.
> 
> -James
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CE45DD84-98D8-406D-A829-CF0C2B7AB86D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Query question

2015-08-17 Thread Lee Hinde
Given this model, I want to find all ProductSale objects that have expired
and where the Person doesn't have a later (unexpired) purchase of the same
product.

class ProductSale(models.Model):
product = models.ForeignKey(Product)
person = models.ForeignKey(Person)
...
date_expires = models.DateField(blank=True, db_index=True)


The closest I've gotten is in the shell where I get a values_list of person
and product for expired and unexpired and then compare the two lists. That
leaves me with a list of tuples, that (due to the size of the list, I
think) I can't use in a query.extra.

Any suggestions would be appreciated.

(and sorry for the lame subject. I couldn't think of a way to be both
succinct and informative.)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMw3z0TwbHUOLwVKg26N5Bc1q6BQ014hsNVCiws1r083nA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Limit initial admin queryset

2015-07-23 Thread Lee Hinde
I have a model - Registrations. 97% of the time a user wants to see
'todays' registrations when viewing this model in admin. Is there a way to
set the initial display of records, but allow full access thereafter?

The example in admin.get_queryset assumes I want to manage each query. In
my case, I only want to manage those the user doesn't initiate.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMwrwAyprMorYOxBd8Lhb%2BA9vt3_XaygFD0MhkEFN4XwhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Easy to use graphical reporting tools for SQL

2015-07-21 Thread Lee Hinde
https://github.com/epantry/django-sql-explorer

You can build the queries and they're available to whomever you want to
give access. This assumes they have access to the django app.



On Mon, Jul 20, 2015 at 2:09 PM, Kevin  wrote:

> In our office we have a Django application that uses a MySQL database.
> Often I am asked to produce various reports that can range from being basic
> dumps of query results or aggregate computations on query results. To do
> this I must connect to the Django shell to use the ORM or write the SQL
> directly. The problem is that it is impossible for the non-developers to
> access reports unless they ask a developer to create the queries, run them,
> and send the result back. This adds to lots of communication overhead and
> delays.
>
> Is there a basic free or open-source application that can connect to MySQL
> and allow non-developers to graphically build their own queries?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzwo_KD_5NHPd7gtN1b9rrCi0F6b%3Do%3DqPYT%3D%3D2W%3DamwSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a plan to modernize Django-admin?

2015-07-21 Thread Lee Hinde
On Sat, Jul 18, 2015 at 12:25 AM, Stuart Longland <
stua...@longlandclan.yi.org> wrote:

> On 18/07/15 11:00, Ezequiel Bertti wrote:
> > Do you already see this project?
> >
> > https://github.com/sshwsfc/django-xadmin
>
> Unfortunately their homepage just swears at me in Chinese.


http://demo.xadmin.io/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMwk4Jq5%2Bs%2BdVcHGiAR%3DLnXepCZ0jSL0vs0XkJZ6p1gz7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing posts to S3

2015-02-11 Thread Lee Hinde
I'm using django storages/boto to push json files to s3 where they are to
be read by a different app.

I'd like to test the file push by using the Test Client to see if the file
is present on S3.

client = Client()
r = client.get(url, content_type="application/json")

In every case, r comes back as:



I can take the  'url' and paste it into my browser and get the file.

So, there's something about the process I'm not understanding. Is this not
what Client is intended for?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMw-gi%2BMMKXRAVA6XbpSXGmCP38rc2c-c2%3DJQ%3D6bOcPc3A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Change keys in values dictionary.

2015-01-05 Thread Lee Hinde
That example was just showing the part of the values 'grab' that was a
problem; in real life I'm getting data from Recipient as well.

On Sun, Jan 4, 2015 at 11:50 AM, Collin Anderson 
wrote:

> Hi,
>
> Why not query it directly from Message?
>
> Message.objects.filter(recipient__user__system_id=user_id).values('id',
> 'subject')
>
> Collin
>
> On Friday, January 2, 2015 8:35:42 PM UTC-5, Lee Hinde wrote:
>>
>> If I do a query:
>>
>> messages = Recipient.objects.filter(user__system_id=user_id).values("
>> message__id","message__subject")
>>
>> and then
>>
>> {"data":list(messages)}
>>
>> jsonify it, I end up with:
>>
>>   "data" : [
>> {
>>   "message__id" : "2f24d132-4321-4d63-868a-21de6fbc0d44",
>>   "message__subject" : "And look, a new subject."
>> }
>>   ],
>>
>> Let's assume there are lots of messages.
>>
>> What's the best way rename the keys? I.e, I'd like "message__id" to be
>> "id".
>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMxqo9gd_6HiUM8wuZmGs2FSOdyJn3qRUUfuvmTgTDuYmA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Change keys in values dictionary.

2015-01-02 Thread Lee Hinde
If I do a query:

messages =
Recipient.objects.filter(user__system_id=user_id).values("message__id","message__subject")

and then

{"data":list(messages)}

jsonify it, I end up with:

  "data" : [
{
  "message__id" : "2f24d132-4321-4d63-868a-21de6fbc0d44",
  "message__subject" : "And look, a new subject."
}
  ],

Let's assume there are lots of messages.

What's the best way rename the keys? I.e, I'd like "message__id" to be "id".

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMwXBvBC2tLTY1mCWyNcJgYe6v1ybpRd16qhRYwJ8Ta%2Bcg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django REST Framework: How to add prefix in URL for versioning

2014-11-05 Thread Lee Hinde
Swap the urls:

 url(r'^v1/', include(v1_urls, namespace="v1"))

url(r'^', include(default_urls, namespace="default")),


On Wed, Nov 5, 2014 at 5:01 AM, Shoaib Ijaz  wrote:

> I am trying to create version for REST application. Here is my URL Examle
>
> www.myapi.com/foo [default version]
> www.myapi.com/v1/foo [version one]
>
> This is the project structure
>
> ├── __init__.py├── settings.py├── urls.py├── default_app│ ├── __init__.py│ 
> ├── serializer.py│ ├── models.py│ ├── views.py│ ├── urls.py│ └── v1_app├── 
> __init__.py├── serializer.py├── models.py├── views.py├── urls.py
>
> *default_app urls.py*
>
> from django.conf.urls import *from default_app import views as df_viewsfrom 
> rest_framework import routers
>
> router = routers.DefaultRouter()
> router.register(r'foo', df_views.viewname, "foo")
> urlpatterns = router.urls
>
> *v1_app urls.py*
>
> from django.conf.urls import *from v1_app import views as ver_viewsfrom 
> rest_framework import routers
>
> router = routers.DefaultRouter()
> router.register(r'foo', ver_views.viewname, "foo")
> urlpatterns = router.urls
>
> *main file for urls.py*
>
> from django.conf.urls import patterns, include, urlfrom defualt_app import 
> urls as default_urlsfrom v1_app import urls as v1_urlsfrom 
> django.contrib.staticfiles.urls import staticfiles_urlpatterns
>
>
>
> urlpatterns += patterns('',
> url(r'^', include(default_urls, namespace="default")),
> url(r'^v1/', include(v1_urls, namespace="v1")))
>
> urlpatterns += staticfiles_urlpatterns()
>
> My issue is, when i using simple url without any prefix then it is working
>
> www.myapi.com/foo
>
> and when i used version prefix v1 or v2 then it throws error [Page not
> found (404)]
>
> www.myapi.com/v1/foo
>
> I got this idea from this link http://stackoverflow.com/a/21839842/1558544
>
> If I don't use middleware class then is this possible to get same result?
>
> Thank you
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMyV_O4zbJpdhbT409KkrP3%2BbM4UsoQgyfKMn8eV_sP2Gw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: tracking intent during password reset process

2014-09-06 Thread Lee Hinde
Both interesting ideas and the intercepting view seems obvious (now that
you've pointed it out.)

Thanks.


On Sat, Sep 6, 2014 at 1:11 AM, James Schneider 
wrote:

> Curious, hen you say 'touch contrib.auth.views.py', you don't mean
> modifying the Django core, do you?
>
>
> Assuming that you are using contrib.auth.views.password_reset (you may
> need to adjust this strategy for a custom view, etc.):
>
> A quick custom view that simply sets a parameter when it calls the generic
> view and a tweak to the URLconf could solve this:
>
> Only need a single URLconf line for something like 'password/reset/' that
> calls the custom view. All password resets will run through this URL
> regardless of 'authorization level', as you put it.
>
> url(r'^password/reset/$', myviews.pass_reset_set_redirect,
> name='password_reset')
>
> In your templates, for each area, such as /instructor/*, the link to the
> password reset would look something like  %}?next=instructor'. This will create a link to a URL path like
> 'password/reset?next=instructor'. How you generate that link (either based
> on context vars or directly in the template) is up to you and your design.
>
> Custom view:
>
> def pass_reset_set_redirect(request):
>
> DEFAULT_LOCATION = 'public'
>
> locations = { 'public': 'public_home', 'instructor':
> 'instructor_home', 'staff': 'staff_home' } # *_home are the names of the
> URL's that will be used for the redirect and should be resolvable by
> reverse(), etc.
>
> # set a default in the event that the ?next=* parameter is something
> that is not a key in locations
> redirect_url = locations[DEFAULT_LOCATION]
>
> # DEFAULT_LOCATION gets used if ?next=blah is not given at all
> if request.GET.get('next', DEFAULT_LOCATION) in locations:
> redirect_url = locations[request.GET.get('next')]
>
> # call the generic view with post_reset_redirect set to our URL name
> with all the benefits of Django doing the hard part of handling the rest of
> the request
> #
> https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.views.password_reset
>
> return contrib.auth.views.password_reset(request, 
> post_reset_redirect=redirect_url)
>
>
> I haven't tested this so YMMV, and it probably needs a couple of imports,
> etc., but I'm hoping you get the idea. This approach is somewhat extensible
> as the locations can be easily expanded to adapt to new 'authorization'
> levels if you decide you need them, or can be pulled from the database, etc.
>
> Someone let me know if I'm way off here, haven't written a FBV for a few
> years.
>
>
>
> On Fri, Sep 5, 2014 at 3:13 PM, Koed00  wrote:
>
>> I've been adding #tags to my auth urls to redirect traffic after signups
>> and resets. This keeps most of the routing intact, but gives you a hook to
>> redirect on in a later stage.
>> However, I'm not using django-registration so I can't give you any
>> examples.
>>
>>
>> On Friday, September 5, 2014 11:23:54 PM UTC+2, Lee Hinde wrote:
>>>
>>> I have three primary levels of access in my project.
>>>
>>> The public at /
>>> Instructors at /instructor/
>>> Staff at /staff/
>>>
>>> The issue is with the password reset process.
>>>
>>> If someone comes to /instructor/ and then goes through the password
>>> reset process I want them to end up at /instructor/ when they're done.
>>> Currently I've got everyone going to
>>> / because I'd rather confuse staff and instructors than the public.
>>>
>>> I'm not sure how to carry their original intended url / level through to
>>> the end of the reset process. I am loath to touch contrib.auth.views.py
>>> for fear of introducing some obscure, or not so obscure, bug.  Users can be
>>> authorized to all three levels so monitoring their user level doesn't work.
>>>
>>> I'm using django registration, hence registration/auth_urls.py and it
>>> occurred to me to just duplicate (or triplicate) the pertinent urls so that
>>> password/reset/complete/ becomes instructor/password/reset/complete/
>>> and I could pass the appropriate next url to extra_context. But that
>>> doesn't seem very DRY so I thought I'd check in here to see if there was a
>>> better way.
>>>
>>> Thanks.
>>>
>>>  --
>> You received this message

tracking intent during password reset process

2014-09-05 Thread Lee Hinde
I have three primary levels of access in my project.

The public at /
Instructors at /instructor/
Staff at /staff/

The issue is with the password reset process.

If someone comes to /instructor/ and then goes through the password reset
process I want them to end up at /instructor/ when they're done. Currently
I've got everyone going to
/ because I'd rather confuse staff and instructors than the public.

I'm not sure how to carry their original intended url / level through to
the end of the reset process. I am loath to touch contrib.auth.views.py for
fear of introducing some obscure, or not so obscure, bug.  Users can be
authorized to all three levels so monitoring their user level doesn't work.

I'm using django registration, hence registration/auth_urls.py and it
occurred to me to just duplicate (or triplicate) the pertinent urls so that
password/reset/complete/ becomes instructor/password/reset/complete/ and I
could pass the appropriate next url to extra_context. But that doesn't seem
very DRY so I thought I'd check in here to see if there was a better way.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMy8NfRxYyQHLbzvuZLO42MQSgcGCYLHuyFCD3CrSdY3mA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flatpages

2014-08-15 Thread Lee Hinde
I just logged into the backend to make sure the django_flatpage_sites table
was populated and it is.


On Fri, Aug 15, 2014 at 2:21 PM, Lee Hinde  wrote:

> Yes.
>
>
> On Fri, Aug 15, 2014 at 2:10 PM, Collin Anderson 
> wrote:
>
>> SITE_ID is set, but is the correct site selected on the flatpage?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzbRnrmOu6bFM3OHcvkkXdbS78C1T8dzvnnDw9__KDHCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flatpages

2014-08-15 Thread Lee Hinde
Yes.


On Fri, Aug 15, 2014 at 2:10 PM, Collin Anderson 
wrote:

> SITE_ID is set, but is the correct site selected on the flatpage?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMyQ8qR1Cx4M8cdLmN-A%3DKkz4WY4xYg1Lv9eWGb4%2B391QQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flatpages

2014-08-15 Thread Lee Hinde
I don't have APPEND_SLASH in my settings and the default is True, so I
don't think that's it.

Also, I used the django extension show_urls and the flatpages url showed up
in the output, so I think it's in the chain.


On Fri, Aug 15, 2014 at 12:19 PM, C. Kirby  wrote:

> There is a warning about APPEND_SLASH = False in the flatpages
> documentation:
>
> Warning
>
> If you set APPEND_SLASH
> <https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-APPEND_SLASH>
> to False, you must remove the slash in the catchall pattern or flatpages
> without a trailing slash will not be matched.
> Could it be that?
>
>
> On Friday, August 15, 2014 1:58:49 PM UTC-5, Lee Hinde wrote:
>
>> Yes, it's a record in the flatpages table on the production side.
>>
>>
>> On Fri, Aug 15, 2014 at 11:43 AM, Collin Anderson 
>> wrote:
>>
>>> I also assume you added the page to the production database and not just
>>> your dev database (if they're different)?
>>>
>>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMyFy8cMin5PU6oBjMj7jxfTgiyMbYS1_FqTNPprPYZgjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flatpages

2014-08-15 Thread Lee Hinde
Yes, it's a record in the flatpages table on the production side.


On Fri, Aug 15, 2014 at 11:43 AM, Collin Anderson 
wrote:

> I also assume you added the page to the production database and not just
> your dev database (if they're different)?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b3aecbf7-9dca-44b7-88e9-49ef80f2fb94%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMxz0OQcPFw4tt7Z4NUO-pcfKbmo4V78Lx76CVsVYCSf9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flatpages

2014-08-15 Thread Lee Hinde
Yes, ALLOWED_HOSTS is set. This site has been in production since late
March, so it's otherwise a going concern. (1.6.x, which I didn't mention
earlier).


On Fri, Aug 15, 2014 at 11:37 AM, Lee Hinde  wrote:

> It's the only page; I'll double-check allowed hosts...
>
> Thanks.
>
>
> On Fri, Aug 15, 2014 at 11:30 AM, C. Kirby  wrote:
>
>> Is it only occurring on the flatpages test page or all your pages (or is
>> that the only page)? Remember you need ALLOWED_HOSTS set in production[1]
>>
>> [1]https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
>>
>>
>> On Friday, August 15, 2014 12:40:43 PM UTC-5, Lee Hinde wrote:
>>>
>>> I added flatpages to a project and got it working fine locally, using
>>> dev server, but I get a 404 accessing my test page when I push to
>>> production.
>>>
>>> Googling the issue,  most common complaints fixed by making sure SITE_ID
>>> was set, and that's in place in my site.
>>>
>>> I'm not using middleware, I'm using the url:
>>>
>>> urlpatterns += patterns('django.contrib.flatpages.views',
>>>
>>> (r'^(?P.*/)$', 'flatpage'),
>>>
>>> )
>>>
>>> I'm not sure how to debug this...
>>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMwyZMxmKuAwtOtkZ%3DHjB_s5MsMhaHFEYChiGKg6xFxU1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flatpages

2014-08-15 Thread Lee Hinde
It's the only page; I'll double-check allowed hosts...

Thanks.


On Fri, Aug 15, 2014 at 11:30 AM, C. Kirby  wrote:

> Is it only occurring on the flatpages test page or all your pages (or is
> that the only page)? Remember you need ALLOWED_HOSTS set in production[1]
>
> [1]https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
>
>
> On Friday, August 15, 2014 12:40:43 PM UTC-5, Lee Hinde wrote:
>>
>> I added flatpages to a project and got it working fine locally, using dev
>> server, but I get a 404 accessing my test page when I push to production.
>>
>> Googling the issue,  most common complaints fixed by making sure SITE_ID
>> was set, and that's in place in my site.
>>
>> I'm not using middleware, I'm using the url:
>>
>> urlpatterns += patterns('django.contrib.flatpages.views',
>>
>> (r'^(?P.*/)$', 'flatpage'),
>>
>> )
>>
>> I'm not sure how to debug this...
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMz%3DaXn5wWkQYnzqGH1YTSowNSJj%3Dwco57VTc5txOitiZg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flatpages

2014-08-15 Thread Lee Hinde
It's /test/. The flatpages admin form won't accept a url that doesn't begin
and end in a slash.


On Fri, Aug 15, 2014 at 10:55 AM, Collin Anderson 
wrote:

> What is your page's url? Does it end with a slash?
>
> --
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMxqM5WCMf_o%2Bv4Ev4T23zcT9eiRnO68hKH8%2BTALRJP0CQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Flatpages

2014-08-15 Thread Lee Hinde
I added flatpages to a project and got it working fine locally, using dev
server, but I get a 404 accessing my test page when I push to production.

Googling the issue,  most common complaints fixed by making sure SITE_ID
was set, and that's in place in my site.

I'm not using middleware, I'm using the url:

urlpatterns += patterns('django.contrib.flatpages.views',

(r'^(?P.*/)$', 'flatpage'),

)

I'm not sure how to debug this...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMx4k-rcotED1wjaXUaeMaahkvuOeVg6VFMpjV7zhC%3DPpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: school website

2014-08-13 Thread Lee Hinde
You might check out: https://github.com/burke-software




On Tue, Aug 12, 2014 at 7:24 AM, ngangsia akumbo  wrote:

> i have a website to build
>
> it will consist of 4 groups
> students, staff, parents and courses
>
> students will have the following
> profile
> update
> delete
> access courses
> student will only access the course they registered in
>
> staffs will be able to just update information
>
> parents
> will have profile, update, delete,  profile access information
>
> course \
> out line of all courses
> only courses registered can be access bu that student
>
> student should also be able to send messages to each other
>
> i have never done this kid of project, i some guideline on how to go about
> with this
>
> thanks for sincere response
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMx0LYObGA%2BrLqMJaaY6%3Dv0vTJbs_vRtzwr0c5ke9xDi3A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Screenshot pdf from AWS hosted django app

2014-07-25 Thread Lee Hinde
On Fri, Jul 25, 2014 at 4:00 PM, Ralph Lewis 
wrote:

> I am hosting a django webapp in AWS and that is running fine, no errors. I
> now want to be able to take a screenshot of the first page of any pdf that
> is uploaded to the webapp. I have not had any luck trying to screenshot a
> pdf with python. I have heard this can be done with PythonMagick, however,
> I have not been able to get ImageMagick to work on my local dev instance.
> Any guidance would be excellent.
>
>
> Do you have a budget?

https://transloadit.com/docs/conversion-robots#document-thumbs

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMwfT_S69Qd6KWa%2BCq%2BO7PVD1F%2BGyzFs%3DH-wZ_5r%3D7iGzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


creating parent record as part of creating the child record

2014-07-16 Thread Lee Hinde
I need help understanding the flow of saving an object when using Model
Forms and Create Views.

I am using a CreateView class and a Model Form to create the line item of
an invoice and the parent invoice as part of the same user process. - It's
one step as far as the user is concerned.

The parent invoice data can be mostly inferred, i.e, current date, current
user, etc. There is some data that I collect on the line item form, that
is, it's posted, but not part of the Form design itself, I'm manually
adding the fields to the template.  Specifically, the "payer" information
is posted, but isn't part of the line-item form (it's a foreign key in the
invoice table)

I need to create the Invoice before I can save the line item object.

I'm not clear on where in the event chain I should add the Invoice record
creation.  I don't think I can access the request in the form methods,
otherwise I might do it in the form save method, or maybe the
clean_invoice() method.

Without the invoice data I don't get to form_valid in my view.

I'm also gathering payment information, which lives in another 'many'
table. I think I'll be able to process that in the form_valid method of the
view, but I'm not there yet.

I've cobbled all of this using function views in other parts of the
project, manually grabbing post values, etc. but I'm circling back here
because I know I have more to learn about how I think django wants to work.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzHhnwL-h%2BcDvvwBg_gOsoUkEPX9nq%2Bxa_1Ufk2zqFRbw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


testing equality in template tag

2014-06-25 Thread Lee Hinde
with view code like so:

import calendar
months_choices = []
for i in range(1,13):
months_choices.append((i, calendar.month_name[i]))
context['months'] = months_choices


and

context['default_month'] = today.month

I have this snippet in a template (my first use of lists like this):


{% for month in months %}

{{ month.1 }}
{% endfor %}



The issue is the  {% if default_month == month.0 %} always returns false...
The rest of the select is properly built - I get a number for the value and
the month name as the label.

Why?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzx%2B4774Ne21djP-EdSAHDL_64DWhZVQYrUYdND%3DBk2%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


All purpose type checking

2014-03-24 Thread Lee Hinde
I have a search form that lets a user pick the field to be searched from a
pop-up. They could enter a date, a string or a number. Sometimes they enter
all of the above and I'm only expecting one of the above.

GET:,

I'm not catching type errors very gracefully and I'm wondering if there's a
general approach to such things, or if I need to hard code the each test.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMyOSpOTpDhhvz9CeZ8CD8_3Zhtz-DkG%3DRA5aD0B%3DYYd1w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Making sure I'm not missing out on some must have Django apps

2013-12-15 Thread Lee Hinde
I googled the list without any problem.

On December 15, 2013 at 2:21:42 PM, Sebastian Morkisch (semo...@googlemail.com) 
wrote:

Some short description of these plugins are appreciated. Maybe a link?

Am Sonntag, 15. Dezember 2013 17:43:32 UTC+1 schrieb Some Developer:
Right so it has been quite awhile since I updated my list of must have
Django apps. I was wondering if anyone had any suggestions?

Currently I use the following in all my Django projects:

Django Debug Toolbar
debug_toolbar_htmltidy
inspector_panel
debug_toolbar_user_panel
South
Django Compressor

Any other apps that I should be using? I'm looking for general purpose
apps rather than specific apps as I can find the specific ones when I
need them.
--
Lee Hinde

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/etPan.52ae3101.df6a0f2.db5d%40Fifteen.local.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Error: XXX is not JSON serializable

2013-11-19 Thread Lee Hinde
Thanks; I'm almost positive. I'll double check. I've worked around the
problem by converting first.


On Tue, Nov 19, 2013 at 12:58 PM, tim  wrote:

> Are you sure have the list() cast in the deployed version of the code?
> Trying to serialize a ValuesListQuerySet directly would give the error you
> mention since repr() of a ValuesListQuerySet looks like a list.
>
>
> On Tuesday, November 19, 2013 12:28:11 PM UTC-5, Lee Hinde wrote:
>>
>> I have an app I'm moving from local dev (mac, python 2.7.2, django 1.5.4)
>> to WebFaction (python 2.7.5.
>>
>> I'm storing record ids like so:
>>
>> section_ids = list(sections.values_list('id', flat=True))
>> request.session['query.section_ids.last'] = section_ids
>>
>>
>> works fine locally and fails on WF with:
>>
>> (as an example)
>>
>>
>> [10892L, 10891L] is not JSON serializable
>>
>>
>> This is the traceback...
>>
>> File 
>> "/home/leedhinde/webapps/myapp/lib/python2.7/django/core/handlers/base.py"
>> in get_response
>>   187. response = middleware_method(request, response)
>> File "/home/leedhinde/webapps/myapp/lib/python2.7/django/
>> contrib/sessions/middleware.py" in process_response
>>   38. request.session.save()
>> File "/home/leedhinde/webapps/myapp/lib/python2.7/django/
>> contrib/sessions/backends/db.py" in save
>>   51. session_data=self.encode(self.
>> _get_session(no_load=must_create)),
>> File "/home/leedhinde/webapps/myapp/lib/python2.7/django/
>> contrib/sessions/backends/base.py" in encode
>>84. serialized = self.serializer().dumps(session_dict)
>> File "/home/leedhinde/webapps/myapp/lib/python2.7/django/core/signing.py"
>> in dumps
>>   100. return json.dumps(obj, separators=(',',
>> ':')).encode('latin-1')
>> File "/usr/local/lib/python2.7/json/__init__.py" in dumps
>>   250. sort_keys=sort_keys, **kw).encode(obj)
>> File "/usr/local/lib/python2.7/json/encoder.py" in encode
>>207. chunks = self.iterencode(o, _one_shot=True)
>> File "/usr/local/lib/python2.7/json/encoder.py" in iterencode
>>   270. return _iterencode(o, 0)
>> File "/usr/local/lib/python2.7/json/encoder.py" in default
>>   184. raise TypeError(repr(o) + " is not JSON serializable")
>>
>>
>> I'm not clear why this wouldn't work. I also haven't figured out testing
>> session updating in the shell for simpler testing.
>>
>> Any pointers would be appreciated.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMxwJ36WaCcSf5-7ijy2766A3WfG0LrbX%3Dnj6BCi0jGC7w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Error: XXX is not JSON serializable

2013-11-19 Thread Lee Hinde
I have an app I'm moving from local dev (mac, python 2.7.2, django 1.5.4)
to WebFaction (python 2.7.5.

I'm storing record ids like so:

section_ids = list(sections.values_list('id', flat=True))
request.session['query.section_ids.last'] = section_ids


works fine locally and fails on WF with:

(as an example)


[10892L, 10891L] is not JSON serializable


This is the traceback...

File
"/home/leedhinde/webapps/myapp/lib/python2.7/django/core/handlers/base.py"
in get_response
  187. response = middleware_method(request, response)
File
"/home/leedhinde/webapps/myapp/lib/python2.7/django/contrib/sessions/middleware.py"
in process_response
  38. request.session.save()
File
"/home/leedhinde/webapps/myapp/lib/python2.7/django/contrib/sessions/backends/db.py"
in save
  51.
session_data=self.encode(self._get_session(no_load=must_create)),
File
"/home/leedhinde/webapps/myapp/lib/python2.7/django/contrib/sessions/backends/base.py"
in encode
  84. serialized = self.serializer().dumps(session_dict)
File "/home/leedhinde/webapps/myapp/lib/python2.7/django/core/signing.py"
in dumps
  100. return json.dumps(obj, separators=(',',
':')).encode('latin-1')
File "/usr/local/lib/python2.7/json/__init__.py" in dumps
  250. sort_keys=sort_keys, **kw).encode(obj)
File "/usr/local/lib/python2.7/json/encoder.py" in encode
  207. chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/lib/python2.7/json/encoder.py" in iterencode
  270. return _iterencode(o, 0)
File "/usr/local/lib/python2.7/json/encoder.py" in default
  184. raise TypeError(repr(o) + " is not JSON serializable")


I'm not clear why this wouldn't work. I also haven't figured out testing
session updating in the shell for simpler testing.

Any pointers would be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzPm9c4YiFkBBdvQ9uDwOnezxGutmgSJvc5kw8d7J-6QQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re:

2013-11-03 Thread Lee Hinde
You want there to be only one BackgroundImage record marked as 'using_image' 
for a given user. I'm saying you should add a field to your User table that 
tracks their BackgroundImage.

On Nov 3, 2013, at 2:43 PM, Aamu Padi  wrote:

> Thank you for the reply Lee. But could please elaborate a little more. :)
> 
> 
> On Mon, Nov 4, 2013 at 2:48 AM, Lee Hinde  wrote:
> 
> On Nov 3, 2013, at 12:23 PM, Aamu Padi  wrote:
> 
> > How to make a model with a yes/no field, if yes that particular object 
> > (image) will be used as the background, and no other image will be selected.
> >
> > I have come with this model:
> >
> > class BackgroundImage(models.Model):
> > user = models.ForeignKey(user)
> > caption = models.CharField(max_length=200)
> > image = models.ImageField(upload_to=get_upload_file_name)
> > using_image = models.BooleanField()
> >
> > But with this I can select all of them, and not only one.
> >
> > Lets take an example of profile picture. A user can have many images, but 
> > he can only select one as a profile picture. So, that if he selects one, 
> > the other will be un-select itself.
> > Hope everybody understood what I mean. Please ask me if didn't understood. 
> > Also please correct me if my model is not correct. Thank you!
> >
> 
> I recently needed a similar thing (one item out of a table being _the_ thing) 
> and decided that host table was the wrong place to store it. It needs to be 
> in the other table, in this case, your user table should have a field that is 
> the key of the profile picture.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6674AFD3-6F4F-4434-8903-B3B1CF43B03B%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re:

2013-11-03 Thread Lee Hinde

On Nov 3, 2013, at 12:23 PM, Aamu Padi  wrote:

> How to make a model with a yes/no field, if yes that particular object 
> (image) will be used as the background, and no other image will be selected. 
> 
> I have come with this model:
> 
> class BackgroundImage(models.Model):
> user = models.ForeignKey(user)
> caption = models.CharField(max_length=200)
> image = models.ImageField(upload_to=get_upload_file_name)
> using_image = models.BooleanField()
> 
> But with this I can select all of them, and not only one.
> 
> Lets take an example of profile picture. A user can have many images, but he 
> can only select one as a profile picture. So, that if he selects one, the 
> other will be un-select itself.
> Hope everybody understood what I mean. Please ask me if didn't understood. 
> Also please correct me if my model is not correct. Thank you!
> 

I recently needed a similar thing (one item out of a table being _the_ thing) 
and decided that host table was the wrong place to store it. It needs to be in 
the other table, in this case, your user table should have a field that is the 
key of the profile picture.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D75EAE65-8A05-4E92-9638-DD89D852800F%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Querying across Generic Relations

2013-10-28 Thread Lee Hinde
I have a table, Credit, that I want to query based on a value several hops
away. There's a CreditLineItems that has a Generic Foreign Key to one of
two tables, each of which has a Foreign Key to the table I want to search.
I've not as yet setup a reverse relation in the related tables.

My question is, given the structure below, how do I return a selection of
Credits based on a value in Registration?

class Credit(models.Model):
""" Model queried """


class CreditLineItem(models.Model):
credit = models.ForeignKey(Credit)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
 #assumed values...
# The GenericForeignKey could point to
class Enrollment(models.Model):
registration = models.ForeignKey(Registration, blank=True)

--OR--

class ProductSale(models.Model):
registration = models.ForeignKey(Registration, blank=True)

class Registration(models.Model):
registration_number =  models.IntegerField(db_index=True)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMz2s2qowuUgs%3DnBOcde6PGTZEEg1qMYJfos-dDE3VOUHA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: while loop in django

2013-09-19 Thread Lee Hinde
Just a stab…

https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#ifchanged

The sample code shows you how to move through a selection and how to test 
changes.


On Sep 19, 2013, at 12:53 AM, Harjot Mann  wrote:

> On Thu, Sep 19, 2013 at 12:45 PM, Leonardo Giordani
>  wrote:
>> Can you perhaps better describe what you are trying to do?
>> Do you need it in a view or in a template?
> 
> 
> In views I want to add two values having same job-id in my app but
> having some other differences. Please tell me how can I do that and
> also I dont know how to use while loop.please tell me.
> 
> -- 
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Testing Permissions in URL Includes

2013-09-13 Thread Lee Hinde

On Sep 13, 2013, at 12:47 PM, Arnold Krille  wrote:

> On Fri, 13 Sep 2013 11:30:44 -0700 Lee Hinde  wrote:
>> So, the question, is there a way to wrap url include calls in a
>> permission check?
> 
> Wrapping a whole url-include would only work when the url-tree is
> rebuild for each request taking into account the requesting user.
> Todays technologies don't do that anymore.
> 

That helps to understand why it works the way it does. Thanks.

> I would encourage you to look at django-braces and just use the
> PermissionRequiredMixin with your class-based-views.
> 

Doing that now.



> Have fun,
> 

Almost always.

> Arnold

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Testing Permissions in URL Includes

2013-09-13 Thread Lee Hinde
Using Django 1.5.x

I have in my project urls.py entries like this:

   url(r'^staff/people/', include('people.urls')),
   url(r'^staff/admin/facility', include('facility.urls')),
   url(r'^staff/admin', include('district.urls')),
   url(r'^staff/section', include('classes.urls')),
   url(r'^staff/product', include('product.urls')),

With class based views, it's
documented
that
you can wrap CBV calls so that once inside, say, 'people.urls' I could do
something like:

(r'^vote/', permission_required('polls.can_vote')(VoteView*.*
as_view())),

I haven't found it in the docs yet, but it looks like I can do similar
things with function views:

url(r'^edit/(?P\d+)', login_required(people_detail)),

The thing is, there are crap-ton of those calls and it'd be nice to check
things higher up in the call chain. Specifically, I'd like to wrap all the
url includes above like:

  url(r'^staff/people/',
permission_required('some_permission_that_youre_staff')
 include('people.urls')),

I.e., check access based on the url path.

But, I've tried that and I get  errors.

I found this:http://djangosnippets.org/snippets/1219/ which does what I
want, but I'm a little nervous about using something written 5 years ago
with django 1.5. Even assuming it works for me, I'm nervous about getting
too far off the built-in tools with authentication and permissions stuff.
it's documented that the core team is smarter than I am.

So, the question, is there a way to wrap url include calls in a permission
check?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: AJAX - Class Based View or Function Based View?

2013-08-29 Thread Lee Hinde
On Wed, Aug 28, 2013 at 11:51 PM, Sarthak Dev wrote:

> I'm working on an app which uses a lot of AJAX requests. Having previously
> used FBVs for handling ajax and returning JSON, how efficient will it be to
> use a CBV for the same? I read the django docs and found 
> mixins
>  for
> it, but haven't figured out if using them and CBVs will help in any way.
>
> Anyone?
>
> If you decide on CBV, there's also 
> django-braces which
has some ajax helpers.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Getting Timezone conversion in template with USE_TZ = False;

2013-08-12 Thread Lee Hinde
I'm displaying a date/time field in template.

Data in the database: 2013-05-30 00:00:00
template tag:   {{ reg.registration_date  }}
as displayed in the web page: May 29, 2013, 5 p.m.

I didn't have a USE_TZ setting until I tried to figure out what was
happening here.

The data I'm playing with now was all migrated from another system directly
to the backend, i.e., I didn't migrate through django.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Simple registration fourm

2013-06-13 Thread Lee Hinde
On Thu, Jun 13, 2013 at 8:54 AM, Jagdeep Singh wrote:

>
>
> On Thursday, 13 June 2013 19:00:57 UTC+5:30, Muhammad Bilal Anjum
> Soharwardi wrote:
>>
>> Can any body give me the code of simple registration form in
>> Django-Python?
>
>
> Try this :
>
> http://code.google.com/p/django-registration/downloads/list?can=1&q=
>
>

Or:  the current code for django-registration :
https://bitbucket.org/ubernostrum/django-registration

and a starter kit of templates:
https://github.com/macdhuibh/django-registration-templates

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




Re:

2013-05-02 Thread Lee Hinde
yes, it looks like they're being responsive with issues in their test suite:

https://github.com/TechEmpower/FrameworkBenchmarks/issues



On Thu, May 2, 2013 at 9:59 AM, Michał Nowotka  wrote:

> According to that webpage:
> http://www.techempower.com/benchmarks/#section=data-r4 django performance
> is really bad comparing to other popular web frameworks. Are there any
> plans to change this situation?
>
> Regards,
> Michal Nowotka
>
>
>

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




Re: Django-Registration/Custom Authentication Issue

2013-04-19 Thread Lee Hinde
Thanks.


On Fri, Apr 19, 2013 at 4:41 AM, Paul Walsh  wrote:

> These are the changes you'll have to make to django-registration, if you
> are using AUTH_USER_MODEL in django 1.5 and inheriting from AbstractUser:
>
>
> https://bitbucket.org/prjts/django-registration/commits/ba31fc3053bfca7eb7a19d912882e50e295adc55
>
>
>
> On Friday, 19 April 2013 11:52:55 UTC+3, Paul Walsh wrote:
>>
>> James Bennet says above that it is compatible, but the latest
>> django-registration code is not compatible with custom user models.
>>
>> RegistrationProfile, for example, still refers directly to User, whereas
>> the new custom user implementation in Django 1.5 require this to be changed
>> in order to work when AUTH_USER_MODEL is actually being used.
>>
>> See the docs here https://docs.**djangoproject.com/en/dev/**
>> topics/auth/customizing/#**referencing-the-user-model
>>
>> Seeing as in Django, we can't override fields when we subclass models, we
>> cannot "subclass the provided stuff" in this case. Of course, we can
>> override forms and views.
>>
>> In a current django app I am working on, and indeed in every Django app I
>> have worked on, the I was happy with the default user model, and extended
>> it with a profile that included language settings, for example - I didn't
>> replace functionality.
>>
>> The Django 1.5 docs refer explicitly to my use case:
>>
>> https://docs.djangoproject.**com/en/dev/topics/auth/**
>> customizing/#extending-django-**s-default-user
>>
>> But, django-registration does not work with this use case.
>>
>>
>>
>>
>> On Wednesday, 17 April 2013 10:51:44 UTC+3, James Bennett wrote:
>>>
>>> Current hg tip is actually 1.5-compatible, in the sense that if you want
>>> to use your own User model, you just subclass the provided stuff and plug
>>> in your model, either importing directly or using the helper function in
>>> Django 1.5.
>>>
>>> django-registration does not do this itself because
>>>
>>> 1. Using Django 1.5's helpers requires either extra complication of the
>>> imports, or a break with Django 1.4 compatibility, and
>>> 2. If you're using a custom User model, you will by definition be
>>> wanting to subclass and override the default fields, validation logic,
>>> etc., since only a User model identical to django.contrib.auth.models.**User
>>> works with the defaults.
>>>
>>  --
>
>

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




Re: Django-Registration/Custom Authentication Issue

2013-04-16 Thread Lee Hinde
Thanks Scott; that turned out to be the issue. I found those references and 
updated them and all is well.

On Apr 16, 2013, at 7:05 PM, Scott Anderson  wrote:

> Django registration is not compatible with custom user models in Django 1.5, 
> as it directly references django.contrib.auth.models.User in several places.
> 
> If you want to maintain your own copy you can swap those refs for those of 
> your own User model.
> 
> -scott
> 
> Via mobile phone
> 
> On Apr 16, 2013, at 9:59 PM, Rainy  wrote:
> 
>> 
>> 
>> 
>> 
>> On Sunday, April 14, 2013 9:49:32 PM UTC-4, Lee Hinde wrote:
>> I'm trying to do a 'simple' registration with just a user email and password 
>> required to create an account. I'm using django-registration with django 
>> 1.5.1 and have created a custom model and the custom model manager. 
>> 
>> I can hit all the registration forms just fine and have copied the example 
>> from the django docs (ignoring, temporarily, the admonition not to do that.).
>> 
>> I've created a custom backend in django-registration, basically to remove 
>> the username requirement. In fact, my custom backend is identical to the 
>> default, minus any references to the username.
>> 
>> When I try to create a new user (i.e, submit the form), from 
>> /accounts/register/ I get the following error:
>> 
>> AttributeError at /accounts/register/
>> Manager isn't available; User has been swapped for 'letters.PCSUser'
>> 
>> The full trace back is:
>> 
>> File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in 
>> get_response
>>   115. response = callback(request, *callback_args, 
>> **callback_kwargs)
>> File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in view
>>   68. return self.dispatch(request, *args, **kwargs)
>> File 
>> "/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/views.py"
>>  in dispatch
>>   79. return super(RegistrationView, self).dispatch(request, *args, 
>> **kwargs)
>> File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in 
>> dispatch
>>   86. return handler(request, *args, **kwargs)
>> File 
>> "/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/views.py"
>>  in post
>>   35. return self.form_valid(request, form)
>> File 
>> "/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/views.py"
>>  in form_valid
>>   82. new_user = self.register(request, **form.cleaned_data)
>> File 
>> "/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/backends/pcs/views.py"
>>  in register
>>   80. 
>> password, site)
>> File "/Library/Python/2.7/site-packages/django/db/transaction.py" in inner
>>   223. return func(*args, **kwargs)
>> File 
>> "/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/models.py"
>>  in create_inactive_user
>>   78. new_user = User.objects.create_user( email, password)
>> File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in 
>> __get__
>>   256. self.model._meta.object_name, self.model._meta.swapped
>> 
>> 
>> No doubt I've left out some needed component to show why this error is 
>> coming up, but I'm not sure what.  I'm grateful for any pointers on where I 
>> should be looking.
>> 
>> 
>> 
>> I believe the issue is that you need to define usermanager on your custom 
>> user, and
>> you will possibly need to inherit from django usermanager and override it to 
>> not
>> use username anywhere. But at the very least, you need to do something like:
>> 
>> import UserManager from wherever
>> class CustomUser(User):
>> objects = UserManager()
>> 
>> 
>>  -ak
>> 
>  

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




Django-Registration/Custom Authentication Issue

2013-04-14 Thread Lee Hinde
I'm trying to do a 'simple' registration with just a user email and
password required to create an account. I'm using django-registration with
django 1.5.1 and have created a custom model and the custom model manager.

I can hit all the registration forms just fine and have copied the example
from the django docs (ignoring, temporarily, the admonition not to do
that.).

I've created a custom backend in django-registration, basically to remove
the username requirement. In fact, my custom backend is identical to the
default, minus any references to the username.

When I try to create a new user (i.e, submit the form), from
/accounts/register/ I get the following error:

AttributeError at /accounts/register/
Manager isn't available; User has been swapped for 'letters.PCSUser'

The full trace back is:

File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in
get_response
  115. response = callback(request, *callback_args,
**callback_kwargs)
File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in
view
  68. return self.dispatch(request, *args, **kwargs)
File
"/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/views.py"
in dispatch
  79. return super(RegistrationView, self).dispatch(request, *args,
**kwargs)
File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in
dispatch
  86. return handler(request, *args, **kwargs)
File
"/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/views.py"
in post
  35. return self.form_valid(request, form)
File
"/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/views.py"
in form_valid
  82. new_user = self.register(request, **form.cleaned_data)
File
"/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/backends/pcs/views.py"
in register
  80.
password, site)
File "/Library/Python/2.7/site-packages/django/db/transaction.py" in inner
  223. return func(*args, **kwargs)
File
"/Users/leehinde/Documents/Clients/ProfessionalCreditSolutions/pcs/pcs/registration/models.py"
in create_inactive_user
  78. new_user = User.objects.create_user( email, password)
File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in
__get__
  256. self.model._meta.object_name, self.model._meta.swapped


No doubt I've left out some needed component to show why this error is
coming up, but I'm not sure what.  I'm grateful for any pointers on where I
should be looking.

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




Re: PostgresSQL or MySql with django?

2013-03-18 Thread Lee Hinde

On Mar 18, 2013, at 9:34 AM, frocco  wrote:

> Thank you for your feedback.
> Other than the docs, is there a good ebook to learn the basics. I just 
> purchased navicat to use.
> 

https://django.2scoops.org/



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




Inline formset with different default values for each "extra" row

2012-12-04 Thread Lee Hinde
For a product up to three different vendors have been identified and I want
to present a row per vendor (which is a fk) so that the user could select
order quantities from each vendor.

If a vendor doesn't have an order quantity, I'd want to ignore it at
form.save() time, rather than reject it.

Pointers are 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: Seeding Foreign Key with known object with Class Based Views

2012-11-27 Thread Lee Hinde
Thanks Sergi; I just realized my earlier response to you is still sitting
in my drafts folder.  This is helpful.



On Mon, Nov 26, 2012 at 12:08 AM, Sergiy Khohlov  wrote:

> I'm proposing  to add form_valid  function  and make  next trick
>
>
>  def form_valid(self, form)
>  # avoid to early savind od the new address
> newaddress  = form.save(commit=False)
># you need to update object by correct client id value. Keep in
> mind that I'm writing  without django from brain only :-)
> newaddress.client_id = self.client_data.id
># now  we are ready to save new address
> newaddress.save()
> return http.HttpResponseRedirect(self.get_success_url())
>
> 2012/11/25 Lee Hinde :
> >
> > On Nov 24, 2012, at 2:41 PM, Sergiy Khohlov  wrote:
> >
> >> I would like to clarify:
> >>
> >> 1) you dont need to add client id to the form
> >> (this value is already  set in your view)
> >>
> >> 2) If you dont know how to  save address let ask
> >> Of course please add your code. I can not hack your PC and understand
> >> your problem.
> >>
> >> thanks, Serge
> >> 2012/11/24 Lee Hinde :
> >>> nt to seed the client id programmatically without presenting a form
> >>>> field to enter what's a known value
> >>
> >> --
> >
> >
> > Thanks for sticking with this.
> >
> > class AddressForm(ModelForm):
> > def __init__(self, *args, **kwargs):
> > super(AddressForm, self).__init__(*args, **kwargs)
> >
> > self.fields['city'].widget.attrs["class"] = 'capme'
> > self.fields['zip'].widget.attrs["class"] = 'zipcode'
> > self.fields['state'].widget.attrs["class"] = 'input-mini
> upper_case'
> >
> > class Meta:
> > model = Address
> > fields =
> ('street_one','street_two','city','state','zip','response_type')
> > exclude = ('client',)
> >
> >
> > class AddressNew(CreateView):
> > model = Address
> > template_name = 'letters/address.html'
> > form_class = AddressForm
> > context_object_name = 'myfields'
> >
> > def get(self, request, *args, **kwargs):
> > set_current_page(request, "", "active", "", "")
> > return super(AddressNew, self).get(request, *args, **kwargs)
> >
> > def get_context_data(self, **kwargs):
> > context = super(AddressNew, self).get_context_data(**kwargs)
> > context['client_data'] =
> get_object_or_404(Client,pk=self.kwargs["pk"])
> > return context
> >
> >
> > Then, in the template I'm putting client_data.id into a hidden field to
> be returned when the form is saved.
> >
> >
> > --
> > 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.
>
>

-- 
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: Seeding Foreign Key with known object with Class Based Views

2012-11-24 Thread Lee Hinde

On Nov 24, 2012, at 2:41 PM, Sergiy Khohlov  wrote:

> I would like to clarify:
> 
> 1) you dont need to add client id to the form
> (this value is already  set in your view)
> 
> 2) If you dont know how to  save address let ask
> Of course please add your code. I can not hack your PC and understand
> your problem.
> 
> thanks, Serge
> 2012/11/24 Lee Hinde :
>> nt to seed the client id programmatically without presenting a form
>>> field to enter what's a known value
> 
> -- 


Thanks for sticking with this.

class AddressForm(ModelForm):
def __init__(self, *args, **kwargs):
super(AddressForm, self).__init__(*args, **kwargs)

self.fields['city'].widget.attrs["class"] = 'capme'
self.fields['zip'].widget.attrs["class"] = 'zipcode'
self.fields['state'].widget.attrs["class"] = 'input-mini upper_case'

class Meta:
model = Address
fields = 
('street_one','street_two','city','state','zip','response_type')
exclude = ('client',)


class AddressNew(CreateView):
model = Address
template_name = 'letters/address.html'
form_class = AddressForm
context_object_name = 'myfields'

def get(self, request, *args, **kwargs):
set_current_page(request, "", "active", "", "")
return super(AddressNew, self).get(request, *args, **kwargs)

def get_context_data(self, **kwargs):
context = super(AddressNew, self).get_context_data(**kwargs)
context['client_data'] = get_object_or_404(Client,pk=self.kwargs["pk"])
return context


Then, in the template I'm putting client_data.id into a hidden field to be 
returned when the form is saved.


-- 
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: Seeding Foreign Key with known object with Class Based Views

2012-11-24 Thread Lee Hinde
Thanks, but that bit of docs shows that there can be a relationship between
models, but doesn't answer the question I was trying to ask which is, how
to create the relationship in data.


On Thu, Nov 22, 2012 at 12:31 AM, Sergiy Khohlov  wrote:

>
> https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-display/
>  switch  Publisher to client  and  books to address
>  :-)
>
> 2012/11/22 Lee Hinde :
> > I have two tables, Client and Address. Address has a foreign key 'client'
> > which points to the client table. I'll make my user enter a client and
> then
> > enter 1-x Addresses. I'll know which client the address is being linked
> to
> > before the record is created, with a url like : /client/3/address/new/.
> >
> > I want to seed the client id programmatically without presenting a form
> > field to enter what's a known value.
> >
> > I've got this working with method based views, (just throw the client id
> in
> > a hidden field. easy peasy) but can't find an example for what seems to
> me
> > to be a real common need using class based views.
> >
> > The closest I've found are examples relating a user to an object, but
> this
> > isn't quite that and I've spent a fair amount of time trying to adapt the
> > example and either the form complains because the client field is
> missing or
> > there's some other problem.
> >
> > Sooo, I'm hoping that there's an existing example/blog post/stackoverflow
> > question that I've missed that someone could point me to that
> demonstrates
> > this process.
> >
> > Thanks and happy thanksgiving for us US residents. I'll be thankful for
> the
> > non-US folk who might be working and would care to take a shot at 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.
>
> --
> 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.



Seeding Foreign Key with known object with Class Based Views

2012-11-21 Thread Lee Hinde
I have two tables, Client and Address. Address has a foreign key 'client'
which points to the client table. I'll make my user enter a client and then
enter 1-x Addresses. I'll know which client the address is being linked to
before the record is created, with a url like : /client/3/address/new/.

I want to seed the client id programmatically without presenting a form
field to enter what's a known value.

I've got this working with method based views, (just throw the client id in
a hidden field. easy peasy) but can't find an example for what seems to me
to be a real common need using class based views.

The closest I've found are examples relating a user to an object, but this
isn't quite that and I've spent a fair amount of time trying to adapt the
example and either the form complains because the client field is missing
or there's some other problem.

Sooo, I'm hoping that there's an existing example/blog post/stackoverflow
question that I've missed that someone could point me to that demonstrates
this process.

Thanks and happy thanksgiving for us US residents. I'll be thankful for the
non-US folk who might be working and would care to take a shot at 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: syncing sqlite3 for Django tutorial

2012-11-21 Thread Lee Hinde
>From the docs:


NAME -- The name of your database. If you're using SQLite, the database will be 
a file on your computer; in that case, NAME should be the full absolute path, 
including filename, of that file. If the file doesn't exist, it will 
automatically be created when you synchronize the database for the first time 
(see below).

What that means is that if the file with the name you provide doesn't exist it 
will be created. But you have to provide a name (and path.)


On Nov 21, 2012, at 3:54 PM, Luisa Beck  wrote:

> I'm starting the Django tutorials and have virtual environments and django 
> installed. I'm working on a Mac 10.6.8, which has sqlite3 already installed.
> 
> I'm working inside a virtual environment. I changed the settings.py file to:
> ENGINE -- 'django.db.backends.sqlite3'
> 
> I left the NAME -- in the settings.py file blank (i.e. '') because the 
> tutorial said "If the file doesn't exist, it will automatically be created 
> when you synchronize the database for the first time."
> 
> But when I run python manage.py syncdb, I get the following error: 
> django.core.exceptions.ImproperlyConfigured: Please fill out the database 
> NAME in the settings module before using the database.
> 
> Why isn't my file automatically created? Or what do I need to do to solve 
> this problem?
> 
> Thank you!
> 
> 
> -- 
> 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/-/nzkQeK5eKf4J.
> 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 many developers have moved to class-based views?

2012-11-11 Thread Lee Hinde
The dev docs are much more informative.


On Sun, Nov 11, 2012 at 10:45 AM, Arnold Krille wrote:

>
> Docs on CBV in django1.4 are a bit sparse to say the least.
>


>
> Have fun,
>
> Arnold
>

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



CBV for Nested Formesets

2012-11-09 Thread Lee Hinde
I'm looking at these two blog posts to help me figure out nested formsets:

http://yergler.net/blog/2009/09/27/nested-formsets-with-django/

http://andreipetre.tumblr.com/post/26203496689/nested-formsets-with-django

The example uses a function view and I was interested using class-based
views, but I can't figure out where to start.

Thanks for any pointers.

 - Lee

-- 
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: Modernizing the Tutorial

2012-10-26 Thread Lee Hinde
On Thu, Oct 25, 2012 at 4:37 PM, Russell Keith-Magee
 wrote:
>
>
> On Thu, Oct 25, 2012 at 9:00 PM, Tomas Neme  wrote:
>>
>> Now that function-based views are being deprecated, or at least that
>> class-based views are being favored, there should be a tutorial with
>> them in the docs, shouldn't it?
>>
>> I don't mean replacing the current one, because that'd raise the entry
>> point a lot, but cloning the original tutorial, but implementing it
>> with class-based views, possibly placing a link to it in the generic
>> views docs page, would go a long way towards generating "good" habits
>> amongst new users, I think.
>
>
> So, as Lachlan pointed out, the current tutorial 4 *does* use class-based
> generic views.
>
> However, there is also scope for a focussed tutorial about class-based views
> in general. IMHO one of the biggest uptake problems around class-based
> views, and class-based generic views, is that there is a big initial
> learning curve, and the reference docs are intimidating.
>
> There is certainly room for improvement here -- either as a much improved
> topic guide, or as a new tutorial. More docs and better docs is always a
> good thing, and if someone wants to volunteer to write them, they get my
> enthusiastic support.
>
> Yours,
> Russ Magee %-)


Folks could check out the dev docs.
(https://docs.djangoproject.com/en/dev/) There is a lot more info on
class-based views.

-- 
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: connecting to existance mysql

2012-10-09 Thread Lee Hinde
On Tue, Oct 9, 2012 at 8:58 AM, Lewis  wrote:
> Hello,
> I have website that build in php and have the database exists, what is the
> process in using django to connect the existance mysql database? is there
> tutorial about this process?

https://docs.djangoproject.com/en/1.4/howto/legacy-databases/

-- 
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 tutorial question

2012-10-06 Thread Lee Hinde

TJ Marbois wrote:

Hi

going thru the Django tutorial - and got to this part:

https://docs.djangoproject.com/en/1.4/intro/tutorial03/#decoupling-the-urlconfs

my editor has a python lint program running...and it complains about 
'include' at the import being written but unused...


is there any reason this is left in for the tutorial? or is this just 
a not needed leftover or error?  I just want to be sure I am not 
missing some detailbecause it works with or without...Im just 
wondering why they left it in.


from  django.conf.urls  import  patterns,  include,  url

urlpatterns  =  patterns('polls.views',
 url(r'^$',  'index'),
 url(r'^(?P\d+)/$',  'detail'),
 url(r'^(?P\d+)/results/$',  'results'),
 url(r'^(?P\d+)/vote/$',  'vote'),
)
--
It's not used in that example. It is a common pattern to use it in more 
complex apps.  It's explained here: 
https://docs.djangoproject.com/en/1.4/topics/http/urls/#include




--
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: DRYing up my forms.py

2012-08-03 Thread Lee Hinde

On Aug 3, 2012, at 9:01 AM, Melvyn Sopacua  wrote:

> On 3-8-2012 17:37, Lee Hinde wrote:
> 
>> self.fields['photo_response'].widget.attrs["class"] = 'date-field 
>> input-small'
>> self.fields['photo_response'].widget.format = '%m-%d-%Y'
>> 
>> 
>> is there a way to consolidate this sort of thing, such that if a field
>> is a date field, it always gets these settings without me having to
>> explicitly set them?
> 
> Well, you almost answered your own question. Subclass the DateField.
> 
> -- 
> Melvyn Sopacua
> 

Thanks, that got me looking in the right place. I think I need to sublcass the 
widget, since I'm concerned with the display of the data, not how it's 
saved/stored?

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



DRYing up my forms.py

2012-08-03 Thread Lee Hinde
I have a lot of this throughout my forms.py files:


self.fields['verification_date'].widget.attrs["class"] = 'date-field
input-small'
self.fields['verification_date'].widget.format = '%m-%d-%Y'

self.fields['mail_response'].widget.attrs["class"] = 'date-field input-small'
self.fields['mail_response'].widget.format = '%m-%d-%Y'

self.fields['photo_response'].widget.attrs["class"] = 'date-field input-small'
self.fields['photo_response'].widget.format = '%m-%d-%Y'


is there a way to consolidate this sort of thing, such that if a field
is a date field, it always gets these settings without me having to
explicitly set them?

-- 
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: Form 'POST' to a database

2012-07-10 Thread Lee Hinde

On Jul 10, 2012, at 8:48 PM, JJ Zolper wrote:

> I honestly just have a general question.
> 
> If I have one database set in my settings file in settings.py and I try to 
> execute a simple HTML Form using 'POST' how do I get that data into my 
> PostgreSQL database?
> 
> In my view do I have to interface with my model and thus the model takes care 
> of the rest?
> 
> https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/
> 
> This link seems to be down the right road I think?
> 
> I'm sorry if this question does not make a lot of sense but I really am 
> trying to find some direction as to how once I have a view, model, urlconf, 
> and settings file with a database tied to it (i checked using the import 
> django.db connection/cursor test) how do I get the request.POST data sent to 
> my database?
> 
> Thanks,
> 
> JJ
> 
I recommend the tutorial. It walks you through the process, soup to nuts.

https://docs.djangoproject.com/en/dev/intro/tutorial01/

-- 
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: database values in a select form.

2012-07-09 Thread Lee Hinde
On Sun, Jul 8, 2012 at 7:39 PM, Michael Elkins  wrote:
> On Sat, Jul 07, 2012 at 08:25:54PM -0700, Lee Hinde wrote:
>>
>> What I'm noticing is that (in dev mode) the choice list for
>> 'employment_status' doesn't update unless I trigger a change, either
>> to the forms.py or restart the dev server.
>>
>> I'm wondering if there's a better place to handle this.
>
>
> Lee,
>
> Here are some examples of the solution to your problem:
>
> http://ilian.i-n-i.org/django-forms-choicefield-with-dynamic-values/
>
> http://stackoverflow.com/questions/3419997/creating-a-dynamic-choice-field
>
> You can do a web search on "form choicefield dynamic" for other discussions
> on the same topic.
>
> me
>

Thanks.

I combined the two tips and have something that works. I appreciate the help.

And, I did google first, really. Just not the right keywords as it turns 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.



database values in a select form.

2012-07-07 Thread Lee Hinde
I have a table, Choice, that is used to build common lists. For
instance, there might be a list "Employment_Status" with values
"Full-Time" and "Part-Time"

I want to use those values in various forms, so in the appropriate
models.py I have:

def _get_list_choices(list):
choices = Choice.on_site.filter(category =
list).values_list('choice', flat=True).order_by('sort_order')
return  tuple(choices)


and then I'd use it like this:

class PersonForm(ModelForm):
household = forms.CharField(
  widget=forms.HiddenInput())
employment_types = _get_list_choices('Employment_Status')
employment_status = ChoiceField(widget=forms.Select, choices =
zip(employment_types,employment_types))


What I'm noticing is that (in dev mode) the choice list for
'employment_status' doesn't update unless I trigger a change, either
to the forms.py or restart the dev server.

I'm wondering if there's a better place to handle this.

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.



AuditTrail

2012-06-17 Thread Lee Hinde
I'm starting a new project that requires auditing and I 
see https://code.djangoproject.com/wiki/AuditTrail and I'm wondering if 
anyone would like to warn me off or point me a different direction.

Based on the write up, AuditTrail looks like it'd do the job, but, it's 
never that easy, right?

-- 
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/-/bF_P5PJrEukJ.
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 and jquery

2012-06-11 Thread Lee Hinde

On Jun 11, 2012, at 11:51 AM, cocoza4 wrote:

>   i tried to retrieve data from django to jquery by using get
> 
>  this is my $get in jquery
> 
>  $.get("/video/", 
> {
> video_page: page_number
> },
> function(data){
> for (var i = 0; i < data.length; i++){
> alert(data[i]['name']);
> }
> });
> 
>  this code calls to view "video" of django
> 
>  def video(request):
> 
> page = int(request.GET['video_page'])
> print page
> obj = Video.objects.all().order_by('date_time')
> 
> return HttpResponse(obj)
>  
>  why i use alert(data[i]['name']); but it prompts undefined?
> 
>  thanks
> 

there may be other ways to do this, but I return json from my views. You can 
then use .getJSON (to be explicit about what's being expected).

Then I run something like this:

   mydict = model_to_dict(obj)

then you need to respond like this:

 return HttpResponse(json.dumps(mydict), mimetype="application/json")


-- 
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: JQuery .get new url is not updating the page

2012-05-19 Thread Lee Hinde

On May 18, 2012, at 8:24 PM, Furqan Malik wrote:

> Thanks for the reply,
> 
> You misunderstood my question.
> 
> Passed_TestCases = data['Data1']; 
> Failed_TestCases = data['Data2'];
> These values are fine, I am using them to create the table.
> 
> My question is once these values come from view.py, I want to change the 
> browser url so that url can be send to others.
> 

You're right, I did.

http://stackoverflow.com/questions/136458/change-the-url-in-the-browser-without-loading-the-new-page-using-javascript


>  
> On Fri, May 18, 2012 at 3:52 PM, Lee Hinde  wrote:
> 
> On May 18, 2012, at 11:52 AM, furqanmlk wrote:
> 
>> Hi there,
>> 
>> I implemented the JQuery to get the data from Database server and display in 
>> the form of table on the page when user click one of the DOM element.
>> I tried ,
>> 
>> JQuery Code:
>> $.get("RunId_TestCases",{Variable:Value},function(data){
>> 
>> 
>> Passed_TestCases = data['Data1'];
>> Failed_TestCases = data['Data2'];
>> //window.location.hash = this.url
>>//window.location.assign(this.url)
> 
> 
> not knowing anything about the page, but you want something more like:
> 
> $("#ID_FOR_THE_FIELD").val(data['Data1']);
> 
>> 
>> using window.location browser url gets changed but page goes to empty page 
>> with data values.
>> 
>> 
>> Can you please help to solve this issue.
>> 
> 

-- 
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: JQuery .get new url is not updating the page

2012-05-18 Thread Lee Hinde

On May 18, 2012, at 11:52 AM, furqanmlk wrote:

> Hi there,
> 
> I implemented the JQuery to get the data from Database server and display in 
> the form of table on the page when user click one of the DOM element.
> I tried ,
> 
> JQuery Code:
> $.get("RunId_TestCases",{Variable:Value},function(data){
> 
> 
> Passed_TestCases = data['Data1'];
> Failed_TestCases = data['Data2'];
> //window.location.hash = this.url
>//window.location.assign(this.url)


not knowing anything about the page, but you want something more like:

$("#ID_FOR_THE_FIELD").val(data['Data1']);

> 
> using window.location browser url gets changed but page goes to empty page 
> with data values.
> 
> 
> Can you please help to solve this issue.
> 

-- 
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: form doing a query for each element of foreign key in select

2012-04-25 Thread Lee Hinde

On Apr 25, 2012, at 2:16 AM, Tom Evans wrote:

> On Wed, Apr 25, 2012 at 5:58 AM, Lee Hinde  wrote:
>> I have a table with four or five foreign keys. Using the default form
>> widgets, a foreign key is represented by a single value select.
>> 
>> I noticed, with debug_tool_bar, that a query is being made for each
>> element of each foreign key select option. Seems like it ought not
>> 
>> I am using
>> 
>> classes = get_object_or_404(Classes, pk=pk)
>> 
>> to load the record. I tried
>> Classes.on_site.select_related().get(pk=pk) without any change.
>> 
>> The question is, is this to be expected?
>> 
> 
> Yes. How else would it get the potential values that can be selected?
> 
> If you want to load all in one query, you can use select_related(). If
> select_related() doesn't help, then your foreign keys are probably
> nullable, which are not automatically loaded with select_related().
> 
> FYI, having each foreign key lookup as a separate query may not be a bad 
> thing.
> If the cardinality of the foreign keys doesn't change much (you don't
> add frequently add potential new values for that foreign key), then it
> is highly likely that those queries would be served from the query
> cache.
> 
> If you are displaying 1 million different forms, but all their foreign
> key lookups can be served from cache, do you think it would be quicker
> to do 1 million queries with 5 joins in each query, with none of the
> queries cached, or 5 million queries, 1 million with no joins and 4
> million served from the query cache?
> 
> Cheers
> 
> Tom
> 


Thanks Tom; I may have been unclear. I would expect at least one query per 
foreign key to load the potential values, but there is a query for each 
potential value. i.e.., one of the foreign keys is to an instructor table. 
There's that query, then there's a query for each instructor as part of the 
class page load.

And yes, I have a lot of nullable foreign keys. In this example, I can have a 
class but not know yet who the instructor will be. I suppose an alternative to 
a nullable key would be to have a default, 'no decision made yet' option. 
Thanks also for the reminder about select_related not following a nullable fk.

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



form doing a query for each element of foreign key in select

2012-04-24 Thread Lee Hinde
I have a table with four or five foreign keys. Using the default form
widgets, a foreign key is represented by a single value select.

I noticed, with debug_tool_bar, that a query is being made for each
element of each foreign key select option. Seems like it ought not

I am using

    classes = get_object_or_404(Classes, pk=pk)

to load the record. I tried
Classes.on_site.select_related().get(pk=pk) without any change.

The question is, is this to be expected?


I'm using a fairly plain form:

{% extends 'district/district_edit_base.html' %}
{% block title %}
{{block.super}}
{% endblock title %}
{% block extra_ready_js %}
    {{block.super}}
     $("#district_list").collapse('show');
{% endblock extra_ready_js %}

{% block content %}

    {% include "simple_fields.html" %}

{% endblock content %}

simple_fields is

http://www.w3.org/1999/html";>
{% csrf_token %}
{% for field in form %}
    
        {{field.label}}
            
              {{field}}  {{ field.help_text }}
              
                {{ field.errors }}
            
            
    
{% endfor %}



    {% if id != 0 %}
        
        
    {% endif %}
     
    
     

    

 

-- 
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: Word Cap Form Labels

2012-04-19 Thread Lee Hinde
Terrific:

.control-label {text-transform: capitalize;}

Thanks.

On Wed, Apr 18, 2012 at 10:27 PM, Jonathan D. Baker <
jonathandavidba...@gmail.com> wrote:

> Not sure about django, but this is easy to do in CSS.
>
> Sent from my iPhone
>
> On Apr 18, 2012, at 11:21 PM, Lee Hinde  wrote:
>
> The default behavior for a form label is to capitalize the first letter -
> 'Report name'. I'd like to capitalize the first letter of each word -
> 'Report Name'. Short of manually over-riding each label, is there a
> built-in way to do that?
>
> 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.



Word Cap Form Labels

2012-04-18 Thread Lee Hinde
The default behavior for a form label is to capitalize the first letter -
'Report name'. I'd like to capitalize the first letter of each word -
'Report Name'. Short of manually over-riding each label, is there a
built-in way to do that?

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.



Re: Is there such a open source django project?

2012-04-17 Thread Lee Hinde
On Tue, Apr 17, 2012 at 3:12 AM, James Deng  wrote:

> Hi all,
>
> I have a case to manage my staff for customer support, basically I need a
> time based schedule table. the point is that we need to know WHO at WHEN
> should take care of WHICH customer, we should be able to input a bunch of
> support schedule, and get a simple view of it.
>
> So my question is, is there any existing django project/module to use
> before I rush to develop it myself?
>
>
I found this -  https://github.com/glamkit/glamkit-eventtools last time I
looked for a scheduling app.

-- 
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: adding html5 field attributes to a model form

2012-04-09 Thread Lee Hinde
Thanks. I'll check that out.

On Apr 9, 2012, at 7:32 PM, creecode wrote:

> Ah I see.  I haven't looked deeper in the code I'd guess the type is being 
> set after you set it deeper in the machinery based on field class?  Perhaps a 
> custom field could accomplish your goal?
> 
> On Monday, April 9, 2012 7:17:56 PM UTC-7, Lee Hinde wrote:
> 
> Thanks for the response, Creecode,
> 
> I've used that for adding class attributes just fine, but in this case I'm 
> trying to change the field 'type' and that's what doesn't seem to work.
> 
> Toodle-l.
> creecode
> 
> 

-- 
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: adding html5 field attributes to a model form

2012-04-09 Thread Lee Hinde

On Apr 9, 2012, at 6:53 PM, creecode wrote:

> Hello Lee,
> 
> On Monday, April 9, 2012 6:14:08 PM UTC-7, Lee Hinde wrote:
> 
> I'm trying to edit the field type in a form that is using the html5 doctype. 
> I've tried two ways:
> 
> Neither works. 
> 
> Am I looking in the wrong place?
> 
> I use both those techniques and they work great for me.  I've use them on 
> many forms for a project I'm working on now.  Some examples from my code...
> 
> brand_name = forms.CharField ( label = _( 'Brand Name' ), max_length = 
> 128,
> widget = forms.TextInput ( attrs = { 'class' : 'span6', 'placeholder' 
> :
> 'enter brand name', } ) )
> 
> ...and...
> 
> def __init__ ( self, *args, **kwargs ):
> 
> super ( AmountPerServing1Form, self ).__init__ ( *args, **kwargs )
> 
> for key in self.fields:
> 
> field = self.fields [ key ]
> 
> field.widget.attrs [ 'class' ] = 'span7'
> 

Thanks for the response, Creecode,

I've used that for adding class attributes just fine, but in this case I'm 
trying to change the field 'type' and that's what doesn't seem to work.


> I don't see anything wrong with your syntax.  Have you tried the usual 
> things?  Make sure you save the file your're editing, restart the server, 
> etc?  And still the form didn't show up with your changes?
> 
> Could there be some browser or other caching going on between you and the 
> server?
> 
> Are you sub-classing those forms for using them directly?
> 
> Toodle-lo
> creecode
> 



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



adding html5 field attributes to a model form

2012-04-09 Thread Lee Hinde
I'm trying to edit the field type in a form that is using the html5 
doctype. I've tried two ways:

class AddressForm(ModelForm):
contact_email = forms.TextInput(attrs={'type': 'email'})

and 

class AddressForm(ModelForm):
def __init__(self, *args, **kwargs):
super(AddressForm, self).__init__(*args, **kwargs)
self.fields['contact_email'].widget.attrs["type"] = 'email'

Neither works. 

Am I looking in the wrong place?


-- 
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/-/wpLL-DHz5fQJ.
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.



Authentication and Modeling question.

2012-03-26 Thread Lee Hinde
I'm working on a rewrite of an app that has three categories of users
and I'm wondering about the best way to link them to the
authentication system:

In-House Staff.
Contractors
Customers who interact via the app.

The in-house staff model doesn't store any address info. Contractor
and Customer have some common attributes  (address, phone number,
email, etc.) but they have completely different relationships to the
rest of the system.

In the current version I have discrete models for each type and I
manually maintain a link to the equivalent of the user profile table.
But I don't have model inheritance available in the current system.

My question is, do you have any general advice for this and how would
you link it to the existing Auth system, or is there a 3rd party auth
system that you'd recommend I look at.

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.



Re: Looking for a round trip example of adding/editing/saving a record using class-based views

2012-03-19 Thread Lee Hinde
On Sun, Mar 18, 2012 at 4:11 PM, Lee Hinde  wrote:
> I'm looking for something like the vote function in step 4 of the tutorial,
> but using class-based views.py. Any pointers would be appreciated.
>
> Thanks.

Specifically, what's the equivalent of this block:



def vote(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the poll voting form.
return render_to_response('polls/detail.html', {
'poll': p,
'error_message': "You didn't select a choice.",
}, context_instance=RequestContext(request))
else:
selected_choice.votes += 1
selected_choice.save()
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('polls.views.results',
args=(p.id,)))

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



Looking for a round trip example of adding/editing/saving a record using class-based views

2012-03-18 Thread Lee Hinde
I'm looking for something like the vote function in step 4 of the tutorial, 
but using class-based views.py. Any pointers would be appreciated.

Thanks.

-- 
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/-/igEcuWG2YqEJ.
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: admin css

2012-03-05 Thread Lee Hinde
On Sun, Mar 4, 2012 at 8:32 PM, Mike Dewhirst  wrote:
> I would like to adjust the admin app's base.css. Nothing outrageous. I just
> want to change all the #999 color values to something a little bit darker so
> screen text is slightly easier to see.
>
> I could write a python script to do that but it feels wrong.
>
> I tried locating somewhere in my project to put my own adjusted base.css but
> can't find exactly where to put it.
>
> collectstatic gets base.css from contrib.admin and puts it into
> /static/admin/css but anything in my project gets put straight into
> /static/css
>
> Is there a simple way to avoid editing the contrib.admin base.css?
>
> Thanks
>
> Mike
>

I think this still works:

http://www.theotherblog.com/Articles/2009/06/02/extending-the-django-admin-interface/

scroll down to "Rebranding Your Django Admin Site"

-- 
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: Building authentication backend

2012-02-01 Thread Lee Hinde
On Feb 1, 2012, at 12:24 AM, apalsson wrote:

> Hello.
> 
> A very simple question.
> 
> I am building an authentication back end to support TWO passwords.
> This requires me to add an extra table to store the secondary password
> plus a ForeignKey to User.
> 
> The confusing part is, how I make Django automatically create the
> needed table when SyncDB is run?
> And how do I make this new table show up in the Admin-interface as
> well?
> 

https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users


-- 
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: Changes to default project layout?

2012-01-12 Thread Lee Hinde
Just following up on this, I don't think my question is answered, 
specifically, which settings.py file is intended to be used?


On Wednesday, November 9, 2011 2:08:47 AM UTC-8, Russell Keith-Magee wrote:
>
> Hi Victor,
>
> All the answers you're looking for are in the draft release notes for
> the 1.4 release:
>
>
> https://docs.djangoproject.com/en/dev/releases/1.4/#updated-default-project-layout-and-manage-py
>
> Yours,
> Russ Magee %-)
>
> On Wed, Nov 9, 2011 at 2:17 PM, Victor Hooi  wrote:
> > heya,
> >
> > Also, I noticed that there's no models.py file in the first app that
> > startproject creates - I assume this is by design, right?
> >
> > Hmm, what's the rationale behind it?
> >
> > Cheers,
> > Victor
> >
> > --
>
> >
>
>

-- 
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/-/LETGA11YF6sJ.
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: mistake in admin home page

2011-02-27 Thread Lee Hinde
On Sun, Feb 27, 2011 at 5:46 AM, vladimir  wrote:
> Please help me, why do I get such a form of admin home page (after
> autentification):
>
> http://www.google.com/url?sa=D&q=https://docs.google.com/leaf%3Fid%3D0B5W4njXO9ND_YmY0ZGQ4NTktZWZiZC00MzU3LWI5ZWEtYTFmM2JkODY5YmEy%26hl%3Den%26authkey%3DCMCK6uQG


Your browser's not finding the admin media location to load the css.
Look at the docs for ADMIN_MEDIA_PREFIX. (I think that's the one...)

-- 
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 unicode in form posts

2011-02-24 Thread Lee Hinde
On Thu, Feb 24, 2011 at 1:32 AM, Tom Evans  wrote:
> On Wed, Feb 23, 2011 at 9:17 PM, Lee Hinde  wrote:
>> Except, now the data that's in the database for the username field
>> goes from looking like this:
>> leehinde
>> to this
>> (u'leehinde',)
>>
>> I'd like it to be 'leehinde' again
>> so, clearly objects.create is more clever than my pure post. But I'm
>> not sure where in the food chain I should be interceding..
>>
>
> http://docs.djangoproject.com/en/1.2/ref/unicode/#general-string-handling
>
> """
> In most cases when Django is dealing with strings, it will convert
> them to Unicode strings before doing anything else. So, as a general
> rule, if you pass in a bytestring, be prepared to receive a Unicode
> string back in the result.
> """
>
> Be prepared :)
>

Thanks Tom; sadly I'm ill-prepared.

a) It's curious that the two django methods (get_or_create vs create)
do different things.
b) I tried wrapping the form fields in str() and got an error, but
I'll play with that some more and figure out why.

I'd found that page, as I really did google 'django unicode, etc.'
before posting. :-) but it assumes more python skill than I have this
week.

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



Problem with unicode in form posts

2011-02-23 Thread Lee Hinde
I had this view function snippet:

   e = Account.objects.create(
user_name = data.get('username'),
password = data.get('password'),
email = data.get('email'),
subscription_number = data.get('subscription_id'),
retrieved = False,
plan  = '60',

)

all was well.

Then the client said, oh, and we need to make sure we don't accept the
same subscription_id more than once.

Ok.

  try:
obj, created =
Account.objects.get_or_create(subscription_number = sub_id)
if created:
obj.user_name = data.get('username'),
obj.password = data.get('password'),
obj.email = data.get('email'),
obj.retrieved = False,
obj.plan  = '60',

obj.save()


Works great.

Except, now the data that's in the database for the username field
goes from looking like this:
leehinde
to this
(u'leehinde',)

I'd like it to be 'leehinde' again
so, clearly objects.create is more clever than my pure post. But I'm
not sure where in the food chain I should be interceding..

-- 
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: [OT]Code Review As a Service

2011-01-25 Thread Lee Hinde
On Tue, Jan 25, 2011 at 7:03 AM, Daniel Roseman  wrote:
> On Tuesday, January 25, 2011 9:42:59 AM UTC, Venkatraman.S. wrote:
>>
>> Hi,
>>
>> I was wondering whether there any freelancers/companies who offer
>> code-review as a service.
>> IMHO, a code review helps in almost all occasions, but the faced paced
>> life seems to have
>> put this in the back burner.
>>
>> Would like your code to be reviewed? If yes, what would be the ideal per
>> hour rates that
>> would not hurt your wallet?
>>
>> -Venkat
>> http://blizzardzblogs.blogspot.com/
>
> Are you asking, or offering? I've done a few successful code reviews for
> people on this group and elsewhere. If you're interested, contact me
> off-list to discuss rates/times.
> --
> Daniel.
>

I'm one of those who used Daniel for a code review and I was extremely
grateful for his 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: Overwhelmed by File upload instructions

2010-07-09 Thread Lee Hinde
I recently struggled with file transfers. After I was done I
discovered django-filetransfers.

http://www.allbuttonspressed.com/projects/django-filetransfers


On Thu, Jul 8, 2010 at 2:55 PM, Rodion Raskolnikiv  wrote:
> Soo easy...
> Thanks for the tips!
> I knew that there had to be a simple solution!!
>
> On Jul 8, 2:02 pm, Daniel Roseman  wrote:
>> On Jul 8, 6:28 pm, Rodion Raskolnikiv  wrote:
>>
>>
>>
>>
>>
>> > Good morning!
>> > I have been wanting to design a model (to be administered via the
>> > admin area) which would allow for file uploads. I have not been able
>> > to grasp a singular, simple approach to this. Perhaps things are
>> > complicated by Django's preference for serving media files under a
>> > different domain, but this is pretty crucial to my project and I was
>> > hoping that someone could point me in the right direction.
>>
>> > This post seems most 
>> > helpful:http://groups.google.com/group/django-users/msg/02cf3d1a838e7e46
>>
>> > but I don't want to blindly copy it and end up with a batch system! I
>> > am just looking to make a simple file uploader.
>>
>> > The model might look like this:
>>
>> > class UploadedFile(models.Model):
>> >     title = models.CharField(max_length=250)
>> >     file = forms.FileField() # I don't know if this is how to define
>> > it
>> >     file_type = models.CharField(max_length=25)
>> >     date_created = models.DateTimeField()
>>
>> > I am a huge fan of Python and Django, and I am often surprised by how
>> > simple and elegant the solutions are, my problem is usually that I am
>> > trying to do things the difficult way...
>>
>> > Any assistance would be greatly appreciated!
>>
>> The documentation for file uploads is indeed complicated, but in order
>> to enable file uploads in the admin you don't need to worry about any
>> of that.
>>
>> However you seem to be trying to declare a form field within a model.
>> You should of course use the models.FileField, which is fully
>> documented 
>> here:http://docs.djangoproject.com/en/1.2/ref/models/fields/#filefield
>> Note that the only thing you *need* to do is to set a value for
>> upload_to.
>> --
>> DR.

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



Booleans not being set in admin

2010-07-08 Thread Lee Hinde
I have a model, Store:

class Store(models.Model):
"""
 Store is use to link users and to provide a target for the weather report.
"""
name = models.CharField(max_length=50, help_text="Simple
Identifier for Store -")
zip_code = models.CharField(max_length=20,help_text = "Used to get
weather data for this store.")
visible = models.BooleanField(default=True,db_index=True,help_text
= "You can setup a store and make them invisible until they're ready
to play..")

objects = models.Manager()
are_visible = StoresAreVisible()

class Meta:
ordering = ('name',)

def __unicode__(self):
return self.name


With this admin.py setup:

class StoreOptions(admin.ModelAdmin):
save_on_top = True
list_display = ('name','zip_code')
inlines = [UserProfileStoreInline,]
search_fields = ['name','zip_code']


Regardless of the 'visible' value, it is always displayed in admin as
true - checked.  If I uncheck it, the database field doesn't change.
If I make the database value 0 'manually,' and play with various
settings, I can't get the database to update on that field.

I've made no other changes to the admin section.

I have other boolean fields which work fine.

Any thoughts on where else I should look?


TIA

 - Lee

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



If you need a code review

2010-07-01 Thread Lee Hinde
I'm new to Django. I've done one modest, search only, public site
prior to my current project. I'm also new to python. While I'm new to
all this, I've been doing web dev. for 14 years.

The site I'm working on now is a low-user intranet for a local
restaurant chain.  I was able to conceptualize the whole thing, there
weren't any real challenges in the design. It's just that the tools
were all new. Google and a stack of books were my friend.

During the course of  my development I ran across a helpful blog post
(http://blog.roseman.org.uk/2010/05/10/django-aggregation-and-simple-group/)
on aggregation that actually provided a working example of something I
was needing to do. I added the blog to my reader list and moved on.

After I was done with the first phase of the project I went looking
for a code review. I was hoping to have someone point out where I was
working too hard, missing pythonic approaches and/or Django features.
And, I went back to the author of the very helpful blog post.

The point of all this is to highly recommend Daniel Roseman
(http://www.roseman.org.uk/) if you're inclined to have someone review
your work.  Mr. Roseman was kind (I was sort of prepared to get ripped
as only one can on the internet.), concise and helpful. We had an hour
and a half of Skype enabled review and I don't feel there was a wasted
minute.

-- 
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: Why is ModelAdmin to Model a 1-1 relationship?

2010-06-26 Thread Lee Hinde
On Fri, Jun 25, 2010 at 2:54 PM, patjenk  wrote:
> In our application, we have a Model that has a boolean field named
> "deleted". When the delete() method is called, we set the deleted
> field to 1 and then save the model. We would like to create an admin
> site where we can manage the deleted and non deleted instances
> separately.
>
> We could accomplish our goal by defining a queryset function for the
> ModelAdmin that restricts the instances returned to deleted=0.
> However, AFAIK this would eliminate the ability to undelete instances
> via the admin. Another option is to allow all instances to be shown
> and include delete as a value in the list_filter list for the admin
> but that clutters up our UI and requires an extra click. It would be
> nice if we could specify that the default admin view for this model
> has a list_filter of deleted=0 but I don't think this is currently
> possible.
>
> I think a good solution would be to create two ModelAdmins. One to
> display active instances and one to display deleted instances. With
> this approach we could define a queryset function for each ModelAdmin
> and when an instance is deleted it would automatically move to the
> correct ModelAdmin. This is explicitly denied in django/contrib/admin/
> sites.py. Simply removing this check does not solve our problem but
> overwrites the first ModelAdmin for the model with the second via the
> dictionary "_registered" in the AdminSite class. From my brief dive
> into the admin site, there doesn't appear to be a real need for a one
> to one relationship between ModelAdmins and Models. If you allowed
> ModelAdmins to specify their own name I think it would be possible to
> have more than one ModelAdmin for a Model. I am not a Django expert
> but I don't see a reason that this scenario should be excluded.
>
> Can anyone recommend a way to accomplish either of the approaches I
> outlined above or propose a new approach that does not violate the
> AdminSite rules? Also, if anyone knows why the ModelAdmin needs to
> have a one to one relationship with Model please let me know.

I recently clipped this for future reference. I believe it will help
you do what you want:

http://www.mahner.org/posts/separating-staff-and-user-accounts-in-djangos-admin/

-- 
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: len() vs count

2010-06-15 Thread Lee Hinde
On Tue, Jun 15, 2010 at 7:56 AM, bruno desthuilliers
 wrote:
> On 14 juin, 22:17, Lee Hinde  wrote:
>> This started off as a pagination question, but then I realized it was
>> a different issue:
>>
>> Given:http://dpaste.com/hold/207217/
>
>
>    u = notes.filter(Q(recipient__user = id) |
> Q(store_as_text="All")).distinct()
>    u = notes.filter(recipient__user = id)
>
> OT but - You're aware that the second statements discards all results
> from the first one ?

I added the 2nd filter to see if the distinct() made a difference in
the outcome. I should have commented the first one out.

>    n = u.select_related().order_by('-target_date','-id')
>    agg = _aggregation(n,request)
>
> What is '_aggregation' ?

_aggregation creates a 2nd queryset

def _aggregation(notes,request):
if _is_manager_or_above(request):
agg = notes.aggregate(Sum('lunch'),Sum('dinner'),Sum('catering'))
else:
agg = {}
agg['lunch__sum'] = Decimal(0)
agg['dinner__sum'] = Decimal(0)
agg['catering__sum'] = Decimal(0)
return agg



> #    print(len(n))
>    paginator = Paginator(n,10)
>
>    try:
>        page = int(request.GET.get('page', '1'))
>    except ValueError:
>        page = 1
>
>    try:
>        paged_notes = paginator.page(page)
>    except (EmptyPage, InvalidPage):
>        paged_notes = paginator.page(paginator.num_pages) #last page.
>
>    print paged_notes.paginator.count
>
>> why would  len(n)  be different  than n.count()
>
> cf my question above.
>

-- 
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: len() vs count

2010-06-14 Thread Lee Hinde
Sorry, I wasn't clear. If I call 'len' (line 5),  the number of
records returned by "paged_notes.paginator.count" process is correct.
If I don't call len, the number returned is off.

On Mon, Jun 14, 2010 at 9:17 PM, Harley Bussell  wrote:
>
> count() does a sql count statement, while len() loads all rows from
> the database and returns the array length of the results.
> count() is much faster and better to use if you can conditionally
> avoid loading all results.
>
> On Jun 15, 6:17 am, Lee Hinde  wrote:
> > This started off as a pagination question, but then I realized it was
> > a different issue:
> >
> > Given:http://dpaste.com/hold/207217/
> >
> > why would  len(n)  be different  than n.count()
> >
> > In my case, the len result is correct, but Paginator tries count first
> > (and uses that value).
>

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



  1   2   >