Starting a Django Project the Right Way

2012-07-26 Thread Frankline
Hi all,

I found this on the internet and thought I should share it.

http://www.jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-way/

By the end of it all, you should have:

1. A fully functional Django project
2. All resources under source control (with git)
3. An environment independet install of your project (using virtualenv)
4. Automated deployment and testing (using Fabric)
5. Automatic database migrations (using South)
6. A solid start to your new site


Regards,
Frankline

-- 
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: Models: Referencing A Model In Another App and Different Project

2012-07-26 Thread JJ Zolper
You are probably right to be honest. I might be overdoing it with 
seperating things apart. I guess sometimes I'm too efficient!

Here's some more to chew on though:

I also want to point out the reason why I am trying to bring one model into 
another.

MadTrak/
 manage.py
 MadTrak/
Artists/
  manage.py
  Artists/
 initialize/
   models.py
Fans/
  manage.py
  Fans/
Venues/
  manage.py
  Venues/
GeoDjango/
  manage.py
  GeoDjango/
 discover/
   models.py

As you can see I have 5 projects. MadTrak, Artists, Fans, Venues, 
GeoDjango. The idea here is that the top level MadTrak project handles 
everything that has to do with the simple about pages etc. The Artists 
project has the artist database in it and same for Fans and Venues 
respectively. And Finally GeoDjango has discover with is my app to 
hopefully be requested by a Fan and pull data from the Artist database and 
return that to the user.

I have no idea to be honest if this thought process is the correct one 
because I'm not that familiar with databases and how my whole directory 
tree here would interact so the advice you might be able to give could be 
entirely priceless to my whole understand of how to build a website with 
Django.

Without the advice it could break my whole building process.

I believe this all makes sense. I have separated out the major parts. The 
major databases of content Artists, Fans, Venues into their own projects 
with their databases and GeoDjango with its spatial database. I just don't 
have the knowledge to be able to connect the dots between how I can 
ACTUALLY call upon the data in my Artists project database and perform 
operations on it within my GeoDjango project.

TO MICHAEL: Question 1 & 2. I don't really have to do it this way probably. 
I could place the code in the same artist project most likely. I might just 
be slightly naive right now when it comes to when to use a "project" and 
when to just break it down into code. The reason I wanted to connect is 
because that I have that separate GeoDjango project just for doing 
geographic type work and that is not in the same project space as Artist 
yet I want to do geographic work with the Artist database so I can return 
data based on the artist. Does that make sense?

Question 3. I probably should but I don't quite feel like I know how to yet.

And Conclusion for Michael: Combining the two sounds better everyday to be 
honest. It might be my best solution. So now that you see my directory tree 
might you be able to give me some advice how to attack this problem? Should 
I put my GeoDjango project in the Artist project? If it makes sense what 
I'm doing (Querying the Artist database in the Artist project with the 
GeoDjango cod) then what do you reccomend I do?

Thanks,

JJ

On Thursday, July 26, 2012 9:14:08 AM UTC-4, (unknown) wrote:
>
> I'm not sure whether there is a good solution for this problem with the 
> prerequisites you mentioned. 
> Just because you import onde model doesn't mean you have full access to 
> the 
> underlying database of another project. 
>
> If nobody comes up with a better idea (I never tried something similar), 
> here 
> is what I think: 
>
> Do you really have to do it this way? Why do you need the connecting link 
> on 
> the model layer? 
> How about creating an interface to query the Artist app? (REST or 
> whatever) 
>
> I'd either do that (REST), or I'd combine these two applications into one 
> project. 
>
> good luck, 
>
> Michael 
>
>
> -Original Message- 
> From: django-users@googlegroups.com on behalf of JJ Zolper 
> Sent: Thu 7/26/2012 3:12 AM 
> To: django-users@googlegroups.com 
> Subject: Models: Referencing A Model In Another App and Different Project 
>   
> Hello fellow Django developers, 
>
> So here is my model that interfaces with my Artists database: 
>
>
>
> from django.db import models 
>
> class Artist(models.Model): 
>   name = models.CharField(max_length=30) 
>   genre = models.CharField(max_length=30)  
>   city = models.CharField(max_length=30)  
>   state = models.CharField(max_length=30)  
>   country = models.CharField(max_length=30) 
>   website = models.UrlField() 
>
>   def __unicode__(self): 
> return self.name 
>
>
>
> Okay now that you see my database backend interface here's where I'm going 
> next. 
>
> I've been working with GeoDjango for some time now. I've created an app 
> within my GeoDjango project called "discover". What's my goal? Well, I 
> want 
> this app to be able to return information to my users. This app will take 
> the 
> given parameters such as "locationfrom" (the user of 

Add a form to admin side

2012-07-26 Thread TRAN PHONG PHU


I need to create a form to admin-side with two fields

   1. Number of code: integer
   2. Value of code: float

How can I do that. This form is not related to any model.

Thank you so much.

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



The idle process does not destroy when request finished

2012-07-26 Thread DanYun Liu
As the visit user is growing fast, I switch the method=threaded to
method=prefork to handle more quest. But the service then become not
available sometimes, I found that one or two processes were created  every
minute and the old ones  still here with CPU usage 0%, idled.

I don't have any idea where I can debug the problem, can anyone share some
suggestions?

thanks

-- 
Pursuit the freedom of the soul.

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



"Django Django" - a band for the next DjangoCon?

2012-07-26 Thread Dave Lampton
We missed them for this upcoming conference, but we gotta get these guys
for the next one, you know, some evening entertainment.  :)

Check them out.  They're actually pretty good.

http://www.djangodjango.co.uk/
http://twitter.com/thedjangos
http://soundcloud.com/djangodjango

-- 
Dave Lampton
http://www.google.com/profiles/dave.lampton

-- 
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: ignore field during form validation

2012-07-26 Thread Zoltan Szalai
In the end I came up with a solution which seems a bit hacky but does 
exactly what I want.

It looks like this:

def clean(self):
cleaned_data = super(Form, self).clean()
check = cleaned_data.get("check", None)

# ignore 'len' when 'check' is False
if not checkand "len" in self._errors:
del self._errors["len"]

return cleaned_data


one thing to note: "len" won't be available in cleaned_data but that's 
just cool since it's not valid :)



On 2012.07.26. 18:29, Kurtis Mullins wrote:
You could remove "required=True" from 'len' and override clean() to 
perform a multiple-field validation. (pretty much what Thomas mentioned)


len() will execute -- it will check to see if it's an integer. If you 
just want to completely ignore it, then do exactly as Thomas said, 
override. But you'll have to make sure you do the "Integer Validation" 
check in your clean() method if you ignore that validation in clean_len().


clean__len():
return self.cleaned_data['len']

On Thu, Jul 26, 2012 at 12:21 PM, Zoltan Szalai > wrote:


On 2012.07.26. 17 :44, Tomas Neme wrote:

class Form(forms.Form):

 check = forms.BooleanField(
 required=False,
 )
 # take into account only when 'check' is True
 len = forms.IntegerField(
 min_value=3,
 max_value=5,
 required=True,
 )


What I want is to validate the 'len' field only when
'check' is True.
I could define the clean method of the form and validate
the required,
min_value and max_value stuff only when 'check' is True
but the case when
someone types a non integer value into the input is still
there. How could I
skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in
it, and
then override clean() and do your check there.


I don't think that would help. The clean method of the Field
(IntegerField in this case) would still run.



--
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: html compress advice

2012-07-26 Thread Phil
ah, thank you. I'll take a look now.

On Thursday, July 26, 2012 10:34:49 PM UTC+1, mhulse wrote:
>
> Hi, 
>
> > Just looking for some advice/ wisdom really. 
>
> While not a direct answer to your question, there was a discussion on 
> the group recently on the topic of the spaceless tag: 
>
> "{% spaceless %} abuse (?)" 
>  
>
> You might find some wisdom there. :) 
>

-- 
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/-/lmKrWiGYzTMJ.
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: html compress advice

2012-07-26 Thread Micky Hulse
Hi,

On Thu, Jul 26, 2012 at 2:29 PM, Phil  wrote:
> Just looking for some advice/ wisdom really.

While not a direct answer to your question, there was a discussion on
the group recently on the topic of the spaceless tag:

"{% spaceless %} abuse (?)"


You might find some wisdom there. :)

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



html compress advice

2012-07-26 Thread Phil
Hi,

Just looking for some advice/ wisdom really.

I have compressed my css/js files and am now looking to strip all the white 
space from the html in the templates to help speed things up as much as 
possible. Is putting my hole base.html file between django's "spaceless" 
template tag an ok way of going about this or would that slow things/ make 
much difference down in the long run?

-- 
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/-/15DFNIBBk80J.
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: newbie URL problem

2012-07-26 Thread Felipe Sitta
I did what you said and put an third parameter on the track view and it 
worked. I think it's not an good practice, because is maintaining useless 
data, but for now its ok, at least the listing is done :D I still have to 
learn to use those regular expressions, its kinda tricky =/

Anyway, thanks to Karen and Daniel for the help, much appreciated!!!

-- 
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/-/AZvprOt4m9EJ.
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: Prefetch related data when using raw()

2012-07-26 Thread akaariai
On 26 heinä, 19:12, Sencha  wrote:
> I want to prefetch related data (ideally through the 
> prefetch_related()method), however I need to use the
> raw() mapper method that will map a custom query (complicated table joins
> to filter my query properly) to my model. However when I try this I get:
>
> AttributeError: 'RawQuerySet' object has no attribute 'prefetch_related'
>
> Is there any way I can achieve the prefetching when using
> Model.objects.raw()?
>
> Many thanks!

There is no direct way. However, you could try this (completely
untested, and not part of public api):

from django.db.models.query import prefetch_related_objects
raw_qs = list(raw_qs) # this line maybe not needed...
prefetch_related_objects(raw_qs, ['a_related_lookup',
'another_related_lookup', ...])

 - Anssi

-- 
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.save() fails silently - how to debug?

2012-07-26 Thread Jirka Vejrazka
Sorry, I should have read your code before answering.

I'm struggling to understand what you do in your clean() method. Are
you sure you're returning the right set of data?

  Jirka

-- 
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.save() fails silently - how to debug?

2012-07-26 Thread Jirka Vejrazka
> Thank you for the suggestion, but unfortunately that too does not work.
>
> I really need to find a way to get at the source of the problem; I would
> think an error message should be generated but none shows up...

Are you doing some magic in model's save() by any chance?

  Jirka

-- 
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.save() fails silently - how to debug?

2012-07-26 Thread Derek
Thank you for the suggestion, but unfortunately that too does not work.  

I really need to find a way to get at the source of the problem; I would 
think an error message should be generated but none shows up...

On Thursday, July 26, 2012 9:47:00 AM UTC+2, Karl Sutt wrote:
>
> I think
>
>> results = formset.save(commit=False)
>> formset.save()
>
> should be
>
>> results = formset.save(commit=False)
>> results.save() 
>
>
> Tervitades/Regards
> Karl Sutt
>
>
> On Thu, Jul 26, 2012 at 10:35 AM, Derek  wrote:
>
>> I'd appreciate some help with the following problem, under Django 1.4
>>
>> When running with the models, forms and view as described below, the data 
>> from the form is *not* saved into the model.
>>
>> However, when using the test code (shown at the end) in a shell 
>> environment, the data *is* saved as expected.
>>
>> How can I tell why the form data is not saved in the view?  It appears to 
>> "fail silently" (i.e. no errors reported) - but adding print statements 
>> into the code reveal that the correct data is available just before the 
>> .save() function.  Is there a preferred approach for debugging this type of 
>> situation?
>>
>> Thanks
>> Derek
>>
>>
>> # models
>> class ClientFile(Model):
>> id = AutoField(primary_key=True)
>> description = CharField(unique=True, max_length=255)
>> file = FileField(upload_to='client', storage=CLIENT_STORAGE)
>>
>>
>> class ClientData(Model):
>> id = AutoField(primary_key=True)
>> clientfile = ForeignKey(ClientFile)
>> #
>> http://code.google.com/p/django-geo/source/browse/trunk/fields.py?r=13#49
>> data_set = DictionaryField(blank=True, null=True)
>>
>>
>> # forms
>> class ClientDataForm(ModelForm):
>>
>> class Meta:
>> abstract = True
>> model = ClientData
>> widgets = {
>> 'data_set': HiddenInput(),
>> 'clientfile': HiddenInput()
>> }
>>
>>
>> class ClientDataFormLayout(ClientDataForm):
>> label = CharField(max_length=255)
>> top_left = CharField(max_length=255)
>> bottom_right = CharField(max_length=255)
>>
>> def __init__(self, *args, **kwargs):
>> super(ClientDataForm, self).__init__(*args, **kwargs)
>>
>> class Meta(ClientDataForm.Meta):
>> pass
>>
>> def clean(self):
>> cleaned = self.cleaned_data
>> # copy for alteration
>> cleaned_data = copy.deepcopy(self.cleaned_data)
>> del cleaned_data['data_set']
>> del cleaned_data['clientfile']
>> cleaned['data_set'] = cleaned_data
>> return cleaned
>>
>>
>> # view
>> client_dataform_layout = ClientDataFormLayout()
>> client = get_object_or_404(ClientFile, pk=1)
>> initial = {'clientfile': client}
>> if request.method == 'POST':
>> formset = client_dataform_layout(request.POST, instance=client)
>> if formset.is_valid():
>> results = formset.save(commit=False)
>> form_data = formset.cleaned_data  #  test only
>> formset.save()
>> else:
>> formset = client_dataform_layout(instance=client, initial=initial)
>> return render_to_response("clients/client_data.html",
>>   locals(),
>>   RequestContext(request))
>>
>>
>> # test code
>> formset = ClientDataFormLayout(data {'clientfile': 1, 'data_set': '',
>>  'top_left': 'AA', 'bottom_right': 
>> 'ZZ',
>>  'label': 'foobar'})
>> print formset.is_valid()
>> results = formset.save(commit=False)
>> formset.save()
>> cd = ClientData.objects.get(clientfile__pk=1)
>> print cd.data_set
>>
>>  -- 
>> 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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/6CvDRwBfrCAJ.
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.



Prefetch related data when using raw()

2012-07-26 Thread Sencha
I want to prefetch related data (ideally through the prefetch_related()method), 
however I need to use the 
raw() mapper method that will map a custom query (complicated table joins 
to filter my query properly) to my model. However when I try this I get:

AttributeError: 'RawQuerySet' object has no attribute 'prefetch_related'

Is there any way I can achieve the prefetching when using 
Model.objects.raw()?

Many 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/-/bUapwzqLvpgJ.
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: ignore field during form validation

2012-07-26 Thread Kurtis Mullins
You could remove "required=True" from 'len' and override clean() to perform
a multiple-field validation. (pretty much what Thomas mentioned)

len() will execute -- it will check to see if it's an integer. If you just
want to completely ignore it, then do exactly as Thomas said, override. But
you'll have to make sure you do the "Integer Validation" check in your
clean() method if you ignore that validation in clean_len().

clean__len():
return self.cleaned_data['len']

On Thu, Jul 26, 2012 at 12:21 PM, Zoltan Szalai wrote:

> On 2012.07.26. 17:44, Tomas Neme wrote:
>
>> class Form(forms.Form):
>>>
>>>  check = forms.BooleanField(
>>>  required=False,
>>>  )
>>>  # take into account only when 'check' is True
>>>  len = forms.IntegerField(
>>>  min_value=3,
>>>  max_value=5,
>>>  required=True,
>>>  )
>>>
>>>
>>> What I want is to validate the 'len' field only when 'check' is True.
>>> I could define the clean method of the form and validate the required,
>>> min_value and max_value stuff only when 'check' is True but the case when
>>> someone types a non integer value into the input is still there. How
>>> could I
>>> skip that? That check is done by the IntegerField.
>>>
>> well, you could override clean_len() and not do anything in it, and
>> then override clean() and do your check there.
>>
>>
> I don't think that would help. The clean method of the Field (IntegerField
> in this case) would still run.
>
>
>
>
> --
> 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+unsubscribe@**
> 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: ignore field during form validation

2012-07-26 Thread Zoltan Szalai

On 2012.07.26. 17:44, Tomas Neme wrote:

class Form(forms.Form):

 check = forms.BooleanField(
 required=False,
 )
 # take into account only when 'check' is True
 len = forms.IntegerField(
 min_value=3,
 max_value=5,
 required=True,
 )


What I want is to validate the 'len' field only when 'check' is True.
I could define the clean method of the form and validate the required,
min_value and max_value stuff only when 'check' is True but the case when
someone types a non integer value into the input is still there. How could I
skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in it, and
then override clean() and do your check there.



I don't think that would help. The clean method of the Field 
(IntegerField in this case) would still run.




--
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: ignore field during form validation

2012-07-26 Thread Tomas Neme
> class Form(forms.Form):
>
> check = forms.BooleanField(
> required=False,
> )
> # take into account only when 'check' is True
> len = forms.IntegerField(
> min_value=3,
> max_value=5,
> required=True,
> )
>
>
> What I want is to validate the 'len' field only when 'check' is True.
> I could define the clean method of the form and validate the required,
> min_value and max_value stuff only when 'check' is True but the case when
> someone types a non integer value into the input is still there. How could I
> skip that? That check is done by the IntegerField.

well, you could override clean_len() and not do anything in it, and
then override clean() and do your check there.

The only problem is that you won't be able to raise the issue as a
field-specific error

-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

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



ignore field during form validation

2012-07-26 Thread Zoltan Szalai

Hi all,

Let's assume i have to the following simple form:


class Form(forms.Form):

check = forms.BooleanField(
required=False,
)
# take into account only when 'check' is True
len = forms.IntegerField(
min_value=3,
max_value=5,
required=True,
)


What I want is to validate the 'len' field only when 'check' is True.
I could define the clean method of the form and validate the required,
min_value and max_value stuff only when 'check' is True but the case when
someone types a non integer value into the input is still there. How 
could I skip that? That check is done by the IntegerField.


The best would be to simply remove the 'len' field of the form when 
'check' is False.
Maybe I could examine request.POST in form's __init__ and according to 
it's content remove the fields I don't care about.

Or is that a terrible idea?


bests
Zoli

--
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: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-26 Thread Tomas Neme
The ArtworkForm AND the full view code would be helpful, yes

also, maybe you'll want to install django-extensions, werkzeug, and
run your devserver with runserver_plus, that'll give you full
debugging capabilities on your browser, and will be able to see what's
each object (that instace object, specifically)

-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

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



Url regex keeps django busy/crashing

2012-07-26 Thread Joe
Hey, I have a url regex like this which is keeping django extremely busy 
(20secs to 1min to handle a request). On some urls it even crashes.

my regex:

url(r'^(?P(\w+-?)*)/$', 'detail'),


view:

def detail(request, item_url):
   i = get_object_or_404(Page, url=item_url,published=True)
   return render_to_response('item/detail.html', {'item':i},
   context_instance=RequestContext(request))

replaced with:

url(r'^(?P[\w-]+)/$', 'detail'),


The replacement works like a charm. What is wrong with the first regex?

Thanks in advance.

-- 
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/-/lVIrewdZipMJ.
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: Automated updating of data across staging and production environments?

2012-07-26 Thread Victor Rocha
I partly agree with the above question. It's a solution, but you usually 
never want to use your production database on a development server. 

As for his problem, I would look into fabric. You can easily write a 
function that dumps data from one database and into another.


On Thursday, July 26, 2012 6:10:33 AM UTC-4, Lloyd Dube wrote:
>
> Hi all,
>
> We have an Ubuntu Linux server which is running virtual environments (one 
> for staging, one for prod.). Our clients test their sites on the staging 
> environment and then proceed to capture the same data on the live sites. 
> They want to be able to, at the click of a button, migrate only the latest 
> data to the live sites. If users have submitted new data (e.g. contact 
> requests) on the prod. server, this data must not be affected.
>
> Is it possible to achieve this, and if so, are there any tools oout there 
> to consider? Any feedback would be appreciated.
>
> Thanks.
>
> -- 
> Regards,
> Sithembewena Lloyd Dube
>

-- 
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/-/aA6OI_LFyk4J.
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: Automated updating of data across staging and production environments?

2012-07-26 Thread Kevin Daum
Sithembewena,
Have you considered using the same database for staging and production? 
Then the problem would be solved by purging the old test data they no 
longer want, which I think would be much easier than partial, conditional 
synchronization. 

Kevin

On Thursday, July 26, 2012 6:10:33 AM UTC-4, Lloyd Dube wrote:
>
> Hi all,
>
> We have an Ubuntu Linux server which is running virtual environments (one 
> for staging, one for prod.). Our clients test their sites on the staging 
> environment and then proceed to capture the same data on the live sites. 
> They want to be able to, at the click of a button, migrate only the latest 
> data to the live sites. If users have submitted new data (e.g. contact 
> requests) on the prod. server, this data must not be affected.
>
> Is it possible to achieve this, and if so, are there any tools oout there 
> to consider? Any feedback would be appreciated.
>
> Thanks.
>
> -- 
> Regards,
> Sithembewena Lloyd Dube
>

-- 
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/-/u82IRzTwfmwJ.
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: Models: Referencing A Model In Another App and Different Project

2012-07-26 Thread michael.pimmer.ext
I'm not sure whether there is a good solution for this problem with the
prerequisites you mentioned.
Just because you import onde model doesn't mean you have full access to the
underlying database of another project.

If nobody comes up with a better idea (I never tried something similar), here
is what I think:

Do you really have to do it this way? Why do you need the connecting link on
the model layer?
How about creating an interface to query the Artist app? (REST or whatever)

I'd either do that (REST), or I'd combine these two applications into one
project.

good luck,

Michael


-Original Message-
From: django-users@googlegroups.com on behalf of JJ Zolper
Sent: Thu 7/26/2012 3:12 AM
To: django-users@googlegroups.com
Subject: Models: Referencing A Model In Another App and Different Project
 
Hello fellow Django developers,

So here is my model that interfaces with my Artists database:



from django.db import models

class Artist(models.Model):
      name = models.CharField(max_length=30)
      genre = models.CharField(max_length=30) 
      city = models.CharField(max_length=30) 
      state = models.CharField(max_length=30) 
      country = models.CharField(max_length=30)
      website = models.UrlField()

      def __unicode__(self):
            return self.name



Okay now that you see my database backend interface here's where I'm going
next.

I've been working with GeoDjango for some time now. I've created an app
within my GeoDjango project called "discover". What's my goal? Well, I want
this app to be able to return information to my users. This app will take the
given parameters such as "locationfrom" (the user of the website inserts
their city, state) and then that value is used to bring in the artists in
their area in relation to the variable "requesteddistance" (which for example
could be 25 mi) along with another variable "genre" (a query on the artists).
So the picture is the user might say I want to see all the "Rock" artists "25
mi" from me in "Vienna, VA".

Now that you can see my project here, here is my question.

In my discover app in the models.py file I could use some help. Through this
discover app I want to be able to reference the Artists database. As you can
see from above the
models.py file has the fields to establish an Artist and their information.
Thus, when a request comes in to the discover app I want to be able to
calculate the requested information and return that. Here's where I'm
stuck... 

In my mind I feel that the appropriate way to do this is to basically create
some sort of ForeignKey in the models.py of discover to the models.py of
Artist? That way I don't have to have two databases of the same data but can
simply reference the Artist database from the discover app.

Another idea I had was instead of creating a "field" link between the two to
try to import the Artist class from the models.py to the models.py file of
the discover app? Then from my views.py file in discover I can process the
given information referenced and return the result.

Any input is welcome. I am striving to use Django's DRY (Don't Repeat
Yourself) methodolgy and try to reference the Artist database and do the
actual processing in the discover application.

Thanks a lot for your advice,

JJ Zolper

-- 
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/-/uypkc91fB9AJ.
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: newbie URL problem

2012-07-26 Thread Karen Tracey
On Thu, Jul 26, 2012 at 8:32 AM, Karen Tracey  wrote:

> On Thu, Jul 26, 2012 at 12:20 AM, Felipe Sitta wrote:
>
>>
>> I messed up with the code and figured that the problem is with the urls
>> patterns. Here are the codes:
>>
>> the url patterns from urls.py
>> url(r'^Track List/(?P(.*)\w+)/$'
>> ,'tracks.views.trackList'),
>> url(r'^Track
>> List/(?P(.*)\w+)/(?P)/$'
>> ,'tracks.views.track'),
>>
>
> Get rid of the (.*) in those url regular expressions.
>

And when you do that you'll also need to adjust your track names to have no
spaces or explicitly allow space in the country/track names, in general it
would be better to slugify your names for use in urls, which will get rid
of spaces and other characters that will wind up getting percent-encoded.
Also the 2nd url pattern seems to be missing the regex pattern part for the
track_name part?

Karen
-- 
http://tracey.org/kmt/

-- 
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: newbie URL problem

2012-07-26 Thread Karen Tracey
On Thu, Jul 26, 2012 at 12:20 AM, Felipe Sitta  wrote:

> I'm new to programming and I'm designing an demo website to get used to
> django, web and database stuff. It's about racetracks.
>
> The structure is the following:
> There's a menu with a link "Track List", it leads to a page with an
> country list each one as a link.
> Each link leads to an list with the racetracks from the respective
> country, and then clicking on a track name leads to a page with
> informations.
>
> So the links will be looking, for example, like this:
>
> localhost/Track List/United States/Indianapolis Motor Speedway
>
>
> Everything's fine until "United States" when I click the track name it
> ignores the view function that creates the track information layout,
> instead of this, it recalls the country list view (which pops an error
> since data is different on the layout)
>
> I messed up with the code and figured that the problem is with the urls
> patterns. Here are the codes:
>
> the url patterns from urls.py
> url(r'^Track List/(?P(.*)\w+)/$'
> ,'tracks.views.trackList'),
> url(r'^Track
> List/(?P(.*)\w+)/(?P)/$'
> ,'tracks.views.track'),
>

Get rid of the (.*) in those url regular expressions. That's matching
anything at all, including '/Indianapolis Motor Speedwa', then the y
matches \w and presumably the url ends with a slash at the end of the
string. urlpatterns are processed in order with first match begin taken, so
anything that that starts with 'Track List' and ends with an alphnumeric
(\w+) and a slash is matching the first url pattern and being routed to
the trackList view.

(Once you get to the point where the 2nd pattern is matched you'll have a
problem since that url captures two parameters for the view but the view
itself is only defined to expect one.)

Karen
-- 
http://tracey.org/kmt/

-- 
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: newbie URL problem

2012-07-26 Thread Daniel Roseman
On Thursday, 26 July 2012 05:20:34 UTC+1, Felipe Sitta wrote:
>
> I'm new to programming and I'm designing an demo website to get used to 
> django, web and database stuff. It's about racetracks.
>
> The structure is the following:
> There's a menu with a link "Track List", it leads to a page with an 
> country list each one as a link. 
> Each link leads to an list with the racetracks from the respective 
> country, and then clicking on a track name leads to a page with 
> informations.
>
> So the links will be looking, for example, like this: 
>
> localhost/Track List/United States/Indianapolis Motor Speedway
>
>
> Everything's fine until "United States" when I click the track name it 
> ignores the view function that creates the track information layout, 
> instead of this, it recalls the country list view (which pops an error 
> since data is different on the layout)
>
> I messed up with the code and figured that the problem is with the urls 
> patterns. Here are the codes:
>
> the url patterns from urls.py
>
> url(r'^Track 
> List/(?P(.*)\w+)/$','tracks.views.trackList'),
> url(r'^Track 
> List/(?P(.*)\w+)/(?P)/$','tracks.views.track'),
>
>
> the views
>
>  def trackList(request, countryList_countryName):
> 
> trackList=Track.objects.filter(country__startswith=countryList_countryName).order_by('name')
> t=loader.get_template('trackList.html')
> c=Context({'tracks':trackList})
> return HttpResponse(t.render(c))
>
> def track(request, track_name):
> track=Track.objects.get(name=track_name)
> t=loader.get_template('track.html')
> c=Context({'track':track})
> return HttpResponse(t.render(c))
>
>
> I'd like to know what should I put on the url pattern to maintain the 
> current url and seek for the next part, the (?P) fragment.
>
> Any help is welcome, thanks to all the community!
>


There are two things wrong here. First, your `track` URL is capturing a 
 `countryList_countryName` parameter in addition to the `track_name` one, 
but the view does not accept it. You should have both parameters in the 
view definition, or just one in the url conf.

Secondly, Django won't actually ever get to the track view, because the 
first URL will match both `/United States/` and `/United 
States/Indianopolis Motor Trackway/', because your regex is greedy. An easy 
way to solve this is to put the urls in the other order, so that it 
attempts to match the one with country+track before trying the country-only 
one.

As an aside, you should avoid using spaces in URLs, and it's also best to 
use all lower case. Make the hard-coded bit something like '/track_list/' 
and use slugs instead of full names for the countries and tracks - 
`/track_list/united-states/indianapolis-motor-speedway/`.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/jQ9aUJrER-AJ.
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: Prevent direct access to some URLs

2012-07-26 Thread Blaxton
I just figured the solution is using @login_required decorator.

Thanks




 From: Blaxton 
To: "django-users@googlegroups.com"  
Sent: Wednesday, July 25, 2012 10:42:31 PM
Subject: Prevent direct access to some URLs
 

Hi
I have set up a login page, using "django.contrib.auth.views.login"
and user's would be forwarded to  their own web page after being 
authenticated, but they can access to their web page directly with 
placing the related uri.

 how can I prevent direct access to those page ?


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.

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



newbie URL problem

2012-07-26 Thread Felipe Sitta
I'm new to programming and I'm designing an demo website to get used to 
django, web and database stuff. It's about racetracks.

The structure is the following:
There's a menu with a link "Track List", it leads to a page with an country 
list each one as a link. 
Each link leads to an list with the racetracks from the respective country, 
and then clicking on a track name leads to a page with informations.

So the links will be looking, for example, like this: 

localhost/Track List/United States/Indianapolis Motor Speedway


Everything's fine until "United States" when I click the track name it 
ignores the view function that creates the track information layout, 
instead of this, it recalls the country list view (which pops an error 
since data is different on the layout)

I messed up with the code and figured that the problem is with the urls 
patterns. Here are the codes:

the url patterns from urls.py

url(r'^Track 
List/(?P(.*)\w+)/$','tracks.views.trackList'),
url(r'^Track 
List/(?P(.*)\w+)/(?P)/$','tracks.views.track'),


the views

 def trackList(request, countryList_countryName):

trackList=Track.objects.filter(country__startswith=countryList_countryName).order_by('name')
t=loader.get_template('trackList.html')
c=Context({'tracks':trackList})
return HttpResponse(t.render(c))

def track(request, track_name):
track=Track.objects.get(name=track_name)
t=loader.get_template('track.html')
c=Context({'track':track})
return HttpResponse(t.render(c))


I'd like to know what should I put on the url pattern to maintain the 
current url and seek for the next part, the (?P) fragment.

Any help is welcome, thanks to all the community!

-- 
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/-/kO2OolPX7YAJ.
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: render a models slug field as a url

2012-07-26 Thread Matthew Meyer
That was it, it is working now. Thank you so much Daniel! :)

On Thursday, July 26, 2012 4:25:10 AM UTC-4, Daniel Roseman wrote:
>
> On Thursday, 26 July 2012 03:45:41 UTC+1, Matthew Meyer wrote:
>>
>> HI daniel, thanks for the reply
>>
>> After your comments, I have used ModelForm to simplify my code. I have 
>> also achieved redirecting the desired url by using the redirect() function. 
>> My issues are still basically the same however:
>>
>> - I do not know how to tell Django to render a template at the redirected 
>> url.
>>
>> I've tried passing redirect differnt views and params etc. to no avail.
>>
>> Here is my new views.py: http://dpaste.org/EtxdP/
>>
>> I am trying to have the event_page view handle the redirect and render 
>> the template it returns. I know I am not relating the redirect and the view 
>> at all, this is because I do not know how. If I try to relate them in some 
>> way like this: return redirect('event_page', event)
>>
>> I get the error: Reverse for 'event_page' with arguments '(> pppzzz>,)' and keyword arguments '{}' not found.
>>
>> My urls.py looks like this now: http://dpaste.org/UzBcR/ 
>>
>> I am sort of hazy on the use of the third parameter in my second url 
>> pattern. I know the first param is a regex, the second is the view that 
>> handles the url, and from what I understand by reading the docs, the third 
>> param is a type of distinguisher used if you are calling the same view for 
>> different urls. 
>>
>> Any thoughts on where I would begin to for rendering a template at the 
>> redirected url?
>>
>> Thanks,
>> Matt
>>
>>
> You haven't quite understood what a redirect is. A redirect doesn't render 
> a template: a redirect is just a signal to the browser to go and fetch 
> another, completely different, URL. Naturally, Django will then reply to 
> that second request with the template rendered by the view pointed to by 
> that second URL.
>
> The third parameter to the url pattern is basically a name Django can use 
> to refer to that URL, so that it can 'reverse' it and produce the actual 
> URL for use in things like links, redirects and permalink definitions.
>
> So, the main problem now is that you probably want the absolute URL to be 
> the `event_page` view. You need to update the get_absolute_url method to 
> point to that URL - as I said above, you can use the short name 'event_url' 
> rather than the fully qualified view name. However, you also need to update 
> the event_page view to accept the `name` parameter, and then to actually 
> get the relevant Event object from that name - eg `event = 
> Event.objects.get(name=name)` - and pass it to the event_page.html template.
> --
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VVxnOTEWDe8J.
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.



Automated updating of data across staging and production environments?

2012-07-26 Thread Sithembewena Lloyd Dube
Hi all,

We have an Ubuntu Linux server which is running virtual environments (one
for staging, one for prod.). Our clients test their sites on the staging
environment and then proceed to capture the same data on the live sites.
They want to be able to, at the click of a button, migrate only the latest
data to the live sites. If users have submitted new data (e.g. contact
requests) on the prod. server, this data must not be affected.

Is it possible to achieve this, and if so, are there any tools oout there
to consider? Any feedback would be appreciated.

Thanks.

-- 
Regards,
Sithembewena Lloyd Dube

-- 
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: Overriding save to create and save related entity

2012-07-26 Thread Sithembewena Lloyd Dube
Thanks guys :)

On Wed, Jul 25, 2012 at 6:49 PM, Mattias Linnap  wrote:

> It is possible to override the save() method in a model to add
> functionality:
>
> https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods
>
> Another choice would be to register a receiver for the pre_save or
> post_save signals:
>
> https://docs.djangoproject.com/en/dev/ref/models/instances#what-happens-when-you-save
> https://docs.djangoproject.com/en/dev/topics/signals/
>
> Either method can be used, the choice depends on your desired
> architecture. I prefer overriding save() for changes to the model
> itself or its related models (as in this case), and signals less
> related features (for example sending an email).
>
> On Wed, Jul 25, 2012 at 4:34 PM, Sithembewena Lloyd Dube
>  wrote:
> > Hi all,
> >
> > I have the following code:
> >
> > class Points(models.Model):
> >  blah blah
> >
> > class TrainingSession(models.Model):
> > confirmed = models.BooleanField()
> > points = models.ForeignKey(Points, null=True, blank=True)
> >
> > When a training session is saved, if confirmed is True I wish to create
> and
> > save a points instance. How can I do so?
> >
> >
> > --
> > Regards,
> > Sithembewena Lloyd Dube
> >
> > --
> > 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.
>
>


-- 
Regards,
Sithembewena Lloyd Dube

-- 
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: render a models slug field as a url

2012-07-26 Thread Daniel Roseman
On Thursday, 26 July 2012 03:45:41 UTC+1, Matthew Meyer wrote:
>
> HI daniel, thanks for the reply
>
> After your comments, I have used ModelForm to simplify my code. I have 
> also achieved redirecting the desired url by using the redirect() function. 
> My issues are still basically the same however:
>
> - I do not know how to tell Django to render a template at the redirected 
> url.
>
> I've tried passing redirect differnt views and params etc. to no avail.
>
> Here is my new views.py: http://dpaste.org/EtxdP/
>
> I am trying to have the event_page view handle the redirect and render the 
> template it returns. I know I am not relating the redirect and the view at 
> all, this is because I do not know how. If I try to relate them in some way 
> like this: return redirect('event_page', event)
>
> I get the error: Reverse for 'event_page' with arguments '( pppzzz>,)' and keyword arguments '{}' not found.
>
> My urls.py looks like this now: http://dpaste.org/UzBcR/ 
>
> I am sort of hazy on the use of the third parameter in my second url 
> pattern. I know the first param is a regex, the second is the view that 
> handles the url, and from what I understand by reading the docs, the third 
> param is a type of distinguisher used if you are calling the same view for 
> different urls. 
>
> Any thoughts on where I would begin to for rendering a template at the 
> redirected url?
>
> Thanks,
> Matt
>
>
You haven't quite understood what a redirect is. A redirect doesn't render 
a template: a redirect is just a signal to the browser to go and fetch 
another, completely different, URL. Naturally, Django will then reply to 
that second request with the template rendered by the view pointed to by 
that second URL.

The third parameter to the url pattern is basically a name Django can use 
to refer to that URL, so that it can 'reverse' it and produce the actual 
URL for use in things like links, redirects and permalink definitions.

So, the main problem now is that you probably want the absolute URL to be 
the `event_page` view. You need to update the get_absolute_url method to 
point to that URL - as I said above, you can use the short name 'event_url' 
rather than the fully qualified view name. However, you also need to update 
the event_page view to accept the `name` parameter, and then to actually 
get the relevant Event object from that name - eg `event = 
Event.objects.get(name=name)` - and pass it to the event_page.html template.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ZNOiBggB8oAJ.
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.save() fails silently - how to debug?

2012-07-26 Thread Karl Sutt
I think

> results = formset.save(commit=False)
> formset.save()

should be

> results = formset.save(commit=False)
> results.save()


Tervitades/Regards
Karl Sutt


On Thu, Jul 26, 2012 at 10:35 AM, Derek  wrote:

> I'd appreciate some help with the following problem, under Django 1.4
>
> When running with the models, forms and view as described below, the data
> from the form is *not* saved into the model.
>
> However, when using the test code (shown at the end) in a shell
> environment, the data *is* saved as expected.
>
> How can I tell why the form data is not saved in the view?  It appears to
> "fail silently" (i.e. no errors reported) - but adding print statements
> into the code reveal that the correct data is available just before the
> .save() function.  Is there a preferred approach for debugging this type of
> situation?
>
> Thanks
> Derek
>
>
> # models
> class ClientFile(Model):
> id = AutoField(primary_key=True)
> description = CharField(unique=True, max_length=255)
> file = FileField(upload_to='client', storage=CLIENT_STORAGE)
>
>
> class ClientData(Model):
> id = AutoField(primary_key=True)
> clientfile = ForeignKey(ClientFile)
> #
> http://code.google.com/p/django-geo/source/browse/trunk/fields.py?r=13#49
> data_set = DictionaryField(blank=True, null=True)
>
>
> # forms
> class ClientDataForm(ModelForm):
>
> class Meta:
> abstract = True
> model = ClientData
> widgets = {
> 'data_set': HiddenInput(),
> 'clientfile': HiddenInput()
> }
>
>
> class ClientDataFormLayout(ClientDataForm):
> label = CharField(max_length=255)
> top_left = CharField(max_length=255)
> bottom_right = CharField(max_length=255)
>
> def __init__(self, *args, **kwargs):
> super(ClientDataForm, self).__init__(*args, **kwargs)
>
> class Meta(ClientDataForm.Meta):
> pass
>
> def clean(self):
> cleaned = self.cleaned_data
> # copy for alteration
> cleaned_data = copy.deepcopy(self.cleaned_data)
> del cleaned_data['data_set']
> del cleaned_data['clientfile']
> cleaned['data_set'] = cleaned_data
> return cleaned
>
>
> # view
> client_dataform_layout = ClientDataFormLayout()
> client = get_object_or_404(ClientFile, pk=1)
> initial = {'clientfile': client}
> if request.method == 'POST':
> formset = client_dataform_layout(request.POST, instance=client)
> if formset.is_valid():
> results = formset.save(commit=False)
> form_data = formset.cleaned_data  #  test only
> formset.save()
> else:
> formset = client_dataform_layout(instance=client, initial=initial)
> return render_to_response("clients/client_data.html",
>   locals(),
>   RequestContext(request))
>
>
> # test code
> formset = ClientDataFormLayout(data {'clientfile': 1, 'data_set': '',
>  'top_left': 'AA', 'bottom_right':
> 'ZZ',
>  'label': 'foobar'})
> print formset.is_valid()
> results = formset.save(commit=False)
> formset.save()
> cd = ClientData.objects.get(clientfile__pk=1)
> print cd.data_set
>
>  --
> 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.



form.save() fails silently - how to debug?

2012-07-26 Thread Derek
I'd appreciate some help with the following problem, under Django 1.4

When running with the models, forms and view as described below, the data
from the form is *not* saved into the model.

However, when using the test code (shown at the end) in a shell
environment, the data *is* saved as expected.

How can I tell why the form data is not saved in the view?  It appears to
"fail silently" (i.e. no errors reported) - but adding print statements
into the code reveal that the correct data is available just before the
.save() function.  Is there a preferred approach for debugging this type of
situation?

Thanks
Derek


# models
class ClientFile(Model):
id = AutoField(primary_key=True)
description = CharField(unique=True, max_length=255)
file = FileField(upload_to='client', storage=CLIENT_STORAGE)


class ClientData(Model):
id = AutoField(primary_key=True)
clientfile = ForeignKey(ClientFile)
#
http://code.google.com/p/django-geo/source/browse/trunk/fields.py?r=13#49
data_set = DictionaryField(blank=True, null=True)


# forms
class ClientDataForm(ModelForm):

class Meta:
abstract = True
model = ClientData
widgets = {
'data_set': HiddenInput(),
'clientfile': HiddenInput()
}


class ClientDataFormLayout(ClientDataForm):
label = CharField(max_length=255)
top_left = CharField(max_length=255)
bottom_right = CharField(max_length=255)

def __init__(self, *args, **kwargs):
super(ClientDataForm, self).__init__(*args, **kwargs)

class Meta(ClientDataForm.Meta):
pass

def clean(self):
cleaned = self.cleaned_data
# copy for alteration
cleaned_data = copy.deepcopy(self.cleaned_data)
del cleaned_data['data_set']
del cleaned_data['clientfile']
cleaned['data_set'] = cleaned_data
return cleaned


# view
client_dataform_layout = ClientDataFormLayout()
client = get_object_or_404(ClientFile, pk=1)
initial = {'clientfile': client}
if request.method == 'POST':
formset = client_dataform_layout(request.POST, instance=client)
if formset.is_valid():
results = formset.save(commit=False)
form_data = formset.cleaned_data  #  test only
formset.save()
else:
formset = client_dataform_layout(instance=client, initial=initial)
return render_to_response("clients/client_data.html",
  locals(),
  RequestContext(request))


# test code
formset = ClientDataFormLayout(data {'clientfile': 1, 'data_set': '',
 'top_left': 'AA', 'bottom_right': 'ZZ',
 'label': 'foobar'})
print formset.is_valid()
results = formset.save(commit=False)
formset.save()
cd = ClientData.objects.get(clientfile__pk=1)
print cd.data_set

-- 
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: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-26 Thread Babatunde Akinyanmi
Like the code for ArtworkForm

On 7/26/12, Babatunde Akinyanmi  wrote:
> Looks good to me. Are you sure have shown us all the relevant parts of
> your code?
>
> On 7/25/12, Deathweasel  wrote:
>> Hello, guys.
>> This is Django 1.4.
>>
>> I have this code from my view:
>>
>> my_art = ArtworkModel.objects.get(id=pk)
>> comments = CommentModel.objects.filter(artwork=pk)
>> artForm = ArtworkForm(instance=my_art)
>> ...
>>
>> These models:
>>
>> class ArtworkModel(models.Model):
>> """
>> This class contains the information necessary to describe a piece
>> of
>> artwork uploaded to my website. Technically, the artist field is
>> unnecessary, but I'm throwing it in because I'd like to be able
>> to upload collaborations.
>> """
>> MEDIUMS = (('ink', 'ink'),
>>('graphite', 'graphite'),
>>('watercolor', 'watercolor'),
>>('oil', 'oil'),
>>('acrylic', 'acrylic'),
>>('digital', 'digital'),
>>('sculpture', 'sculpture'),
>>('other','other'))
>>
>> title = models.CharField(max_length=200)
>> medium = models.CharField(max_length=200, choices=MEDIUMS,
>> default='graphite')
>> upload_date = models.DateTimeField(auto_now_add=True)
>> artist = models.CharField(max_length=200)
>> image = models.ImageField(upload_to=getFilePath)
>> desc = models.TextField(verbose_name="Description", max_length=500)
>>
>> class Meta:
>> ordering = ['title']
>>
>> def __unicode__(self):
>> return '-'.join((self.title, self.artist, self.medium))
>>
>> class CommentModel(models.Model):
>> """
>> This class contains the information necessary to describe a
>> comment
>> that someone's left about a piece of artwork.
>> """
>> commenteer = models.CharField(max_length=200, blank=False)
>> comment_body = models.TextField(blank=False)
>> artwork = models.ForeignKey(ArtworkModel)
>> date = models.DateTimeField(auto_now_add=True)
>>
>> class Meta:
>> ordering = ['date']
>>
>>
>> And this traceback:
>> Traceback:
>> File
>> "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py"
>> in get_response
>>   111. response = callback(request,
>> *callback_args,
>>
>> **callback_kwargs)
>> File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py"
>> in
>>
>> _wrapped_view
>>   91. response = view_func(request, *args, **kwargs)
>> File "/home/deathweasel/shiny-website/deathweasel/artwork/views.py" in
>> modify_artwork
>>   94. artForm = ArtworkForm(instance=my_art)
>> File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in
>> __init__
>>   238. object_data = model_to_dict(instance, opts.fields,
>> opts.exclude)
>> File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in
>> model_to_dict
>>   111. opts = instance._meta
>>
>> Exception Type: AttributeError at /artwork/8/modify/
>> Exception Value: 'QuerySet' object has no attribute '_meta'
>>
>> The internet says I should be using a regular Model instance rather than
>> a
>> QuerySet to populate my form. The thing is that I think I AM using a
>> regular model. I'm not even using
>> those CommentModels yet. I don't understand why this is failing? Please
>> help?
>>
>> --
>> 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/-/_eRwn1qmzr0J.
>> 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.
>>
>>
>
> --
> Sent from my mobile device
>

-- 
Sent from my mobile device

-- 
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: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-26 Thread Babatunde Akinyanmi
Looks good to me. Are you sure have shown us all the relevant parts of
your code?

On 7/25/12, Deathweasel  wrote:
> Hello, guys.
> This is Django 1.4.
>
> I have this code from my view:
>
> my_art = ArtworkModel.objects.get(id=pk)
> comments = CommentModel.objects.filter(artwork=pk)
> artForm = ArtworkForm(instance=my_art)
> ...
>
> These models:
>
> class ArtworkModel(models.Model):
> """
> This class contains the information necessary to describe a piece
> of
> artwork uploaded to my website. Technically, the artist field is
> unnecessary, but I'm throwing it in because I'd like to be able
> to upload collaborations.
> """
> MEDIUMS = (('ink', 'ink'),
>('graphite', 'graphite'),
>('watercolor', 'watercolor'),
>('oil', 'oil'),
>('acrylic', 'acrylic'),
>('digital', 'digital'),
>('sculpture', 'sculpture'),
>('other','other'))
>
> title = models.CharField(max_length=200)
> medium = models.CharField(max_length=200, choices=MEDIUMS,
> default='graphite')
> upload_date = models.DateTimeField(auto_now_add=True)
> artist = models.CharField(max_length=200)
> image = models.ImageField(upload_to=getFilePath)
> desc = models.TextField(verbose_name="Description", max_length=500)
>
> class Meta:
> ordering = ['title']
>
> def __unicode__(self):
> return '-'.join((self.title, self.artist, self.medium))
>
> class CommentModel(models.Model):
> """
> This class contains the information necessary to describe a comment
> that someone's left about a piece of artwork.
> """
> commenteer = models.CharField(max_length=200, blank=False)
> comment_body = models.TextField(blank=False)
> artwork = models.ForeignKey(ArtworkModel)
> date = models.DateTimeField(auto_now_add=True)
>
> class Meta:
> ordering = ['date']
>
>
> And this traceback:
> Traceback:
> File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py"
> in get_response
>   111. response = callback(request, *callback_args,
>
> **callback_kwargs)
> File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in
>
> _wrapped_view
>   91. response = view_func(request, *args, **kwargs)
> File "/home/deathweasel/shiny-website/deathweasel/artwork/views.py" in
> modify_artwork
>   94. artForm = ArtworkForm(instance=my_art)
> File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in
> __init__
>   238. object_data = model_to_dict(instance, opts.fields,
> opts.exclude)
> File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in
> model_to_dict
>   111. opts = instance._meta
>
> Exception Type: AttributeError at /artwork/8/modify/
> Exception Value: 'QuerySet' object has no attribute '_meta'
>
> The internet says I should be using a regular Model instance rather than a
> QuerySet to populate my form. The thing is that I think I AM using a
> regular model. I'm not even using
> those CommentModels yet. I don't understand why this is failing? Please
> help?
>
> --
> 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/-/_eRwn1qmzr0J.
> 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.
>
>

-- 
Sent from my mobile device

-- 
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: Testing against a multi-db app with un-managed models [django 1.2.3]

2012-07-26 Thread Xavier Ordoquy
Hi Kit

I've been working with a similar problem to solve. I was using Django 1.3.0.
In my case, the legacy database could not be either created nor loaded with 
fixtures as it had lots of composite keys - which is something Django can't 
handle.
The workaround I used to run tests was to override the database driver and 
database creation classes to create the database from sql. I had also to 
override the TestCase so I could do a simple rollback after every test instead 
of recreating the full database - I was using postgres and its database 
creation is extremely long.

If I remember correctly I've faced some issues while overriding the test 
runner, but I can't remember them.

I don't have much informations as I'm on vacation. If you poke me by the end of 
next week I will give you more informations.

Good luck,
Xavier Ordoquy,
Linovia.

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