Thursday, May 31, 2012

Make ManyToMany field editable in a ModelForm

Yes, how does one do that?
Right now it's just rendering static choices that already exist. Or do I have to circumvent ModelForm for this field and present the field manually?

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

Re: App inside another app or nesting in django apps

1.6.2012 9:16, Derek kirjoitti:
> And the Zen of Python?
>
> "Flat is better than nested"

But don't forget, again Zen of Python:

"Namespaces are one honking great idea -- let's do more of those!"


>
> On Jun 1, 8:10 am, Jani Tiainen<rede...@gmail.com> wrote:
>> 31.5.2012 19:22, Kurtis Mullins kirjoitti:
>>
>>> Sure. They're just Python modules. All you need to do is:
>>
>>> 1. Include the files: __init__.py and models.py
>>> 2. Add the application to your settings.py, for example: myproject.myapp.subapp
>>
>>> It *should* work, although I haven't personally tested it yet.
>>
>>> On Thu, May 31, 2012 at 7:46 AM, vijay shanker<vshanker...@gmail.com> wrote:
>>>> can we write one app inside some another django-app .
>>>> please suggest any reference or articles
>>
>> It works perfectly. We've been using it in our environment for a good while.
>>
>> There lies only one caveat - all appnames still must be unique and as
>> known app name is last part of module hierarchy.
>>
>> So you can't have two conflicting apps:
>>
>> myapp.subapp<-- appname is subapp
>> myotherapp.subapp<-- appname is subapp
>>
>> --
>> Jani Tiainen
>>
>> - Well planned is half done and a half done has been sufficient before...
>


--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

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

Re: App inside another app or nesting in django apps

And the Zen of Python?

"Flat is better than nested"

On Jun 1, 8:10 am, Jani Tiainen <rede...@gmail.com> wrote:
> 31.5.2012 19:22, Kurtis Mullins kirjoitti:
>
> > Sure. They're just Python modules. All you need to do is:
>
> > 1. Include the files: __init__.py and models.py
> > 2. Add the application to your settings.py, for example:  myproject.myapp.subapp
>
> > It *should* work, although I haven't personally tested it yet.
>
> > On Thu, May 31, 2012 at 7:46 AM, vijay shanker<vshanker...@gmail.com>  wrote:
> >> can we write one app inside some another django-app .
> >> please suggest any reference or articles
>
> It works perfectly. We've been using it in our environment for a good while.
>
> There lies only one caveat - all appnames still must be unique and as
> known app name is last part of module hierarchy.
>
> So you can't have two conflicting apps:
>
> myapp.subapp          <-- appname is subapp
> myotherapp.subapp     <-- appname is subapp
>
> --
> Jani Tiainen
>
> - Well planned is half done and a half done has been sufficient before...

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

Re: App inside another app or nesting in django apps

31.5.2012 19:22, Kurtis Mullins kirjoitti:
> Sure. They're just Python modules. All you need to do is:
>
> 1. Include the files: __init__.py and models.py
> 2. Add the application to your settings.py, for example: myproject.myapp.subapp
>
> It *should* work, although I haven't personally tested it yet.
>
> On Thu, May 31, 2012 at 7:46 AM, vijay shanker<vshanker.88@gmail.com> wrote:
>> can we write one app inside some another django-app .
>> please suggest any reference or articles

It works perfectly. We've been using it in our environment for a good while.

There lies only one caveat - all appnames still must be unique and as
known app name is last part of module hierarchy.

So you can't have two conflicting apps:

myapp.subapp <-- appname is subapp
myotherapp.subapp <-- appname is subapp

--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

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

Re: Adding values to formdata of ModelForm before saving

One minor edit to that:
form.save(request) -> form.save(request, kalender)

On Thu, May 31, 2012 at 8:47 PM, Kurtis Mullins <kurtis.mullins@gmail.com> wrote:
Hey,

I tried re-writing your view and form for you -- but I ran into a snag. I don't read German so other than code-wise (and a couple of obvious words, like kalender and participants) I'm not really sure what you're trying to accomplish.

I do see one obvious issue, though. Participants is a many-to-many field in your Model and you're also using the same attribute in your form. Here's something you could try in your form and view:

View:
--------
if request.method == 'POST':
    form = MyForm(request.POST)
    if form.is_valid():
        form.save(request)

Form:
---------
def save(self, request, kalender, commit=True):

    # Get an Instance of the Termin object.
    obj = super(Termin, self).save(commit=True)
  
    # Add the user as a participant if 'add_me' = True
    if self.cleaned_data['add_me']:
        obj.participants.add(request.user)

    # Set the Calendar, Save, and return
    obj.in_calendar = kalender
    obj.save()
    return obj

Hopefully I didn't just confuse you more :) Good luck!

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

Re: Adding values to formdata of ModelForm before saving

Hey,

I tried re-writing your view and form for you -- but I ran into a snag. I don't read German so other than code-wise (and a couple of obvious words, like kalender and participants) I'm not really sure what you're trying to accomplish.

I do see one obvious issue, though. Participants is a many-to-many field in your Model and you're also using the same attribute in your form. Here's something you could try in your form and view:

View:
--------
if request.method == 'POST':
    form = MyForm(request.POST)
    if form.is_valid():
        form.save(request)

Form:
---------
def save(self, request, kalender, commit=True):

    # Get an Instance of the Termin object.
    obj = super(Termin, self).save(commit=True)
  
    # Add the user as a participant if 'add_me' = True
    if self.cleaned_data['add_me']:
        obj.participants.add(request.user)

    # Set the Calendar, Save, and return
    obj.in_calendar = kalender
    obj.save()
    return obj

Hopefully I didn't just confuse you more :) Good luck!

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

Re: Adding values to formdata of ModelForm before saving

On 31 mai, 20:09, Schmidtchen Schleicher <spiolli...@googlemail.com>
wrote:
> Thank you for your quick answer, but it doesn't really work. It raises the
> exception "can't assign to operator"
> My view now looks like this:
>
> @login_required
> > def create_termin(request, calid, year=None, month=None, day=None):
> >     kalender = get_object_or_404(Kalender,pk=int(calid))

You don't need the int conversion here

> >     if request.method == "POST":
> >         print(request.POST)
> >         form = NewTerminForm(request.POST)
>
> >         if form.is_valid():
> >             formdata = form.cleaned_data
> >             if formdata['participants']:
> >                 form.participants = request.user.id
> >             form.save(commit=False)
> >             form.in_calendar-id = kalender

"in_calendar-id" is not a valid Python identifier. It's parsed as
"form.in_calendar - id = kalender"

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

Re: OpenSource IDE with debugger capabilities of PyCharm

On Thu, May 31, 2012 at 6:54 PM, Andre Terra <andreterra@gmail.com> wrote:
> No IDE recommendations, please!
>
> There are many threads regarding that, so please search around, OP.
>
> As for template debugging, this is currently a limitation in Django itself
> AFAIK, but efforts are being made to improve the situation.

It is? And there are? That's news to me - can you shed any light on this?

Yours,
Russ Magee %-)

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

Working Django forums code for integration?

Dear Django-users,

Any recommendations on a Django forums package that's up to date and integrate-able with an existing Django?

Checked www.djangopackages.com and tried PyBBM, DjangoBB, & others, but the code is either too tangled to integrate cleanly with another site, or the code is for an older version of Django & not up to date. Any success or recommendations on which forums packages are easiest to integrate?

Thanks,

-Michael

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

Re: How to add Google Map Markers With Django Template Tags

On 31 May 2012, at 21:21, DF wrote:

That's interesting, but mine seems like it could be less involved. This is what I attempted, which failed:

http://dpaste.org/55T9x/

Well, you don't need all the other stuff I discussed, but the key thing is: given some variable (in my example it was place.site.maps) containing a collection of places with lat/long information, you may be able to use my template to do what you need with a little tweaking.

Daniele

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

MyUser model on Inline

hello guys, I have this MyUser class with a OTO to auth.User. I was trying to make an inline for it with form=UserCreationForm, however django complains that the object doesn't have a set_password method (as expected), so, is ok to inherit as in MyUser(auth.User) on this case, even though it does not seem to be well accepted?

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

Re: How to add Google Map Markers With Django Template Tags

That's interesting, but mine seems like it could be less involved. This is what I attempted, which failed:

http://dpaste.org/55T9x/

On Thursday, May 31, 2012 12:32:26 PM UTC-4, DF wrote:
I'm trying to place markers based on the latitude and longitude stored in a model on a Google Map using the API and HTML5 geolocation.

The issue is how to loop through the lat/lon info for each object stored in the database within JavaScript tags using template keywords, which I'm not sure can be done in Django.

I found a similar question which I mildly modified and placed within a template – not a separate script file – but it doesn't seem to work:

    function loadMarkers(){
            {% for story in stories %}
            var point = new google.maps.LatLng({{story.latitude}},{{story.longitude}});
                var marker = new google.maps.Marker({
                position: point,
                map: map
            });
            {% endfor %}    
        }

Any insight on how to properly loop through items in a stored Django object with lat, lon info and place these on a Google Map using the API would be very appreciated.

On Thursday, May 31, 2012 12:32:26 PM UTC-4, DF wrote:
I'm trying to place markers based on the latitude and longitude stored in a model on a Google Map using the API and HTML5 geolocation.

The issue is how to loop through the lat/lon info for each object stored in the database within JavaScript tags using template keywords, which I'm not sure can be done in Django.

I found a similar question which I mildly modified and placed within a template – not a separate script file – but it doesn't seem to work:

    function loadMarkers(){
            {% for story in stories %}
            var point = new google.maps.LatLng({{story.latitude}},{{story.longitude}});
                var marker = new google.maps.Marker({
                position: point,
                map: map
            });
            {% endfor %}    
        }

Any insight on how to properly loop through items in a stored Django object with lat, lon info and place these on a Google Map using the API would be very 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/-/016Mbbw0JsoJ.
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.

Re: Scaling django installation

I don't think anyone will be able to give you a good evaluation
without knowing more about the requests. Django itself could probably
handle 10k requests per second returning a simple "hello world"
response, or less than 10 if you are returning very large/difficult to
generate responses. It is what your app does that is going to make
all the difference.

The djangobook.com site has some good info on scaling, despite being
for a much older version of django. Ignore the code, and skip down
the the section on scaling:
http://www.djangobook.com/en/1.0/chapter20/

From my own experience, caching/memcache can make all the difference
in the world. Find out what is taking the time, and cache it.
Different approaches to your page design can help too. If the page is
95% identical for all users, cache the 95% and pull in the 5% with
javascript to personalize. Allowing something like varnish to sit in
front of those expensive to generate, but cachable pages is another
way to speed things up but it requires a bit of application specific
configuration to be useful (ignoring cookies for certain urls, making
sure you are setting the vary header correctly in your app, etc).

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

django 1.4, wsgi, flex deploy best practices

I use Flex for the client side and XML between client and server.  I am a “one man team” and so elegance sometimes gets sacrifices for “it works”.   My typical deploy has been

/var/www/html/my flex swf and html code

And

/home/projectname/current/djangositename

 

This works well, except that I have to use absolute URL’s in Flex (including the server name) because Flex will use either absolute or relative to the location of the .swf file.  This means I have to rebuild for different servers.

 

Are there any recommendations of “best practices”

1.       I could have the django view return the html page that includes the swf file.  This has the advantage of allowing django to pass in some flashvars to the application,  the disadvantage is closer coupling (at least for deploy) of client and server; or

2.       I could use the url redirect to allow a relative reference to get redirected to my django home.

 

I’m not an Apache expert and so I defer to the community which is more experienced with these issues for a clean, generic solution I can use going forward as I port to Django 1.4 and CentOs 6.

Re: Scaling django installation

Bump!

On Wednesday, May 30, 2012, Subhranath Chunder wrote:
As the subject suggests, wanted to discuss, acquire and share some knowledge on scaling django installation.

Firstly, my current project is a product Reviews platform, and I wanted to benchmark or load test the current deployment.
Currently the deployment/installation stands on a single server setup.
- Single Amazon EC2 instance m1.xlarge
- Apache Webserver (serving django and static)

To load test I used loadimpact.com and the results of which can be found on:
The test configuration consisted of 600 VUs with 10 mins step duration.
Got around .1 millions requests and around 200+ requests/sec max. Is this good, bad, or at par?

- What might be the possible suggestions for scaling this installation?
- Does separating out media server helps much, and upto what extent?
- Can a single server setup handle 1k to 10k requests/sec?
- Some tools for benchmarking and performance testing?
- Other cost effective ways to scale up the installation?
- What sort of django installation needs to be there to handle 10k requests/sec and .1 million parallel users at all time?
- Any good reads on scaling/scalable django deployment or installation. Sort of guide.

--
Thanks,
Subhranath Chunder.



--
Thanks,
Subhranath Chunder.

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

Re: Adding values to formdata of ModelForm before saving

Thank you for your quick answer, but it doesn't really work. It raises the exception "can't assign to operator"
My view now looks like this:

@login_required
def create_termin(request, calid, year=None, month=None, day=None):
    kalender = get_object_or_404(Kalender,pk=int(calid))
    if request.method == "POST":
        print(request.POST)
        form = NewTerminForm(request.POST)

        if form.is_valid():
            formdata = form.cleaned_data
            if formdata['participants']:
                form.participants = request.user.id
            form.save(commit=False)
            form.in_calendar-id = kalender
            form.save()
            return HttpResponse(pprint.pformat(formdata) + pprint.pformat(inspect.getmembers(form['participants'])) + "\n\n" + pprint.pformat(inspect.getmembers(request.user)),mimetype="text/plain")

    else:
        date = datetime.date(month=int(month), day=int(day), year=int(year)) if day else None
        print("viewdate",date)
        form = NewTerminForm(initial={'date':date,})
    return render_to_response("kalender/new_termin.html", dict(debug=1, calid=calid,form=form, ),context_instance=RequestContext(request))

Am Mittwoch, 30. Mai 2012 23:03:49 UTC+2 schrieb jondbaker:
Yes, it is possible:

obj = form.save(commit=False)
obj.in_calender-id = kalender
obj.save()


On Wed, May 30, 2012 at 2:56 PM, Schmidtchen Schleicher <spiollinux@googlemail.com> wrote:
Is it possible to put missing data into the data of a form before calling form.save() ?
I want to add the calendar-id (calid/in_calendar) before saving to the model.

 http://susepaste.org/23451355

I tried adding it after instantiating the form with form.in_calendar_id = kalender but it didn't work
I don't want to use hidden fields because manipulating them is easy

Maybe https://groups.google.com/forum/?fromgroups#!topic/django-users/F5yHH-G5QLM describes how to solve it but I didn't understand it.

PS: If you find very ugly code please correct me -- I'm a beginner

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



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

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

RE: Webservice return pdf

Here's how I merge .fdf with pdf

def getPDFContent(assessment):
completedfdf = getCompletedForm(assessment)
pdffilename = getFilename(assessment, 'forms') +".pdf"
pdftk = ["/usr/bin/pdftk" ,'pdftk'][os.name=='nt']
cmd = '%s %s fill_form - output - flatten' % (pdftk,
pdffilename)
proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
shell=True, bufsize=100000000)
cmdout,cmderr = proc.communicate(completedfdf)
if cmderr != '':
raise cmderr
return cmdout

and here's how I do my response (from views.py)
def getpdf(request, *args, **kwargs):
qs = extract_querystring_from_request(request)
parameters = Parameters(**qs)
assessment = models.Assessment.objects.get(pk=parameters.id)
pdfbuffer = pdfgenerator.getPDF(assessment)
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'inline; filename=filename.pdf'
response.write(pdfbuffer)
return response

I'm no expert, but this works consistently.

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

Re: How to add Google Map Markers With Django Template Tags

On Thu, May 31, 2012, DF <donfernandez@gmail.com> wrote:

>Any insight on how to properly loop through items in a stored Django object
>with lat, lon info and place these on a Google Map using the API would be
>very appreciated.

I do it like this:

<https://github.com/evildmp/Arkestra/blob/master/contacts_and_people/templates/contacts_and_people/place_map.html>

The view for that template is:

<https://github.com/evildmp/Arkestra/blob/master/contacts_and_people/views.py#L234>

It provides the template with the place; the place ("Building" in the models, before I realised I needed to be concerned with places that were not actual buildings) will belong to a Site. Each Site can have one or more Buildings (i.e. places), each of which might have a map.

The Site.maps property in:

<https://github.com/evildmp/Arkestra/blob/master/contacts_and_people/models.py#L36>

contains a list of Buildings that should have a map for each Site.

The template loops over all those buildings to produce the map, right here:

<https://github.com/evildmp/Arkestra/blob/master/contacts_and_people/templates/contacts_and_people/place_map.html#L45>

Results look for example like:

<http://www.aikidocardiff.com/place/talybont-sports-centre/map/>

or

<http://medicine.cf.ac.uk/place/heath-park-henry-wellcome-building/map/>.

However many items are on the map, it will scale to fit them in its bounds.

Let me know here or on irc://irc.freenode.net/arkestra if you need more information.

Daniele

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

use of threading.Thread causes db connection leak

I discovered our webserver was leaking db connections because of the
use of threading.Thread in combination with the Django ORM. Looking
through the Django 1.4 release notes it seems that connection objects
are safe to share among threads. Is there something special that I
need to do to make sure the connections are closed? The background
threads are definitely terminating (they do a calculation and then put
the result in a Queue.Queue)

Some information about our setup:
Hosted on Heroku (Nginx)
Django 1.4
Postgres 9.1.3
psycopg 2.4.3

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

How to add Google Map Markers With Django Template Tags

I'm trying to place markers based on the latitude and longitude stored in a model on a Google Map using the API and HTML5 geolocation.

The issue is how to loop through the lat/lon info for each object stored in the database within JavaScript tags using template keywords, which I'm not sure can be done in Django.

I found a similar question which I mildly modified and placed within a template – not a separate script file – but it doesn't seem to work:

    function loadMarkers(){
            {% for story in stories %}
            var point = new google.maps.LatLng({{story.latitude}},{{story.longitude}});
                var marker = new google.maps.Marker({
                position: point,
                map: map
            });
            {% endfor %}    
        }

Any insight on how to properly loop through items in a stored Django object with lat, lon info and place these on a Google Map using the API would be very 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/-/zTEN_VxzQkAJ.
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.

Re: App inside another app or nesting in django apps

Sure. They're just Python modules. All you need to do is:

1. Include the files: __init__.py and models.py
2. Add the application to your settings.py, for example: myproject.myapp.subapp

It *should* work, although I haven't personally tested it yet.

On Thu, May 31, 2012 at 7:46 AM, vijay shanker <vshanker.88@gmail.com> wrote:
> can we write one app inside some another django-app .
> please suggest any reference or articles
>
> --
> 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: 404 message

On Thu, May 31, 2012 at 12:37 AM, Stanley Lee <stanigator@gmail.com> wrote:
> Am I supposed to see a 404 message upon completing this section of the
> tutorial? https://docs.djangoproject.com/en/1.4/intro/tutorial03/
>
copy and paste the traceback

> Sorry for the brevity as I'm trying to make the question concise.
> Thanks in advance!
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>



--
Joel Goldstick

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

Re: Admin Inline empty extra - how to access parent form model ID?

I found a noce solution, it only needs this tiny patch already proposed on the tracker :
https://code.djangoproject.com/ticket/17856
There's no reason this patch could not be merged in the trunk, it's self-contained

With this, I can override get_inline_instances in my ModelAdmin :

    def get_inline_instances(self, request, obj):
        inline_instances = []
        for inline_class in self.inlines:
            if inline_class.model == get_model('coop_local', 'Exchange'):
                inline = inline_class(self.model, self.admin_site, obj=obj)
            else:
                inline = inline_class(self.model, self.admin_site)
            inline_instances.append(inline)
        return inline_instances

The inline gets the obj parameter , puts it in a local attribute and deletes it to not bother the Inline superclass

class ExchangeInline(admin.StackedInline):

    def __init__(self, *args, **kwargs):
        self.parent_object = kwargs['obj']
        del kwargs['obj']  # superclass will choke on this
        super(ExchangeInline, self).__init__(*args, **kwargs)

    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'location':
            kwargs['queryset'] = self.parent_object.locations()
        return super(ExchangeInline, self).formfield_for_dbfield(db_field, **kwargs)

An finally in formfield_for_dbfield I can use parent_object to correctly filter my queryset, and this filtering works in any line of the formset : those which are bound to existing objects and the blank (extra ) ones !



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

App inside another app or nesting in django apps

can we write one app inside some another django-app .
please suggest any reference or articles

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

Re: sqlall fails silently

On May 31, 8:24 am, vijay shanker <vshanker...@gmail.com> wrote:
> hi
> i defined three models and put them in /appname/models/ a.py, b.py,
> c.py. and a __init__.py in which i import all classes defined inside
> a.py/b.py/c.py.
>
> when i try to do a ./manage.py sqll appname at prompt , it simply
> passes of without any output.
>  what could be possibly done to debug it .. i had put the appname in
> installed_apps, other app respond to sqlall printing related mysql
> queries .

You need to set your model's Meta app_label :
https://docs.djangoproject.com/en/1.3/ref/models/options/#app-label

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

Re: OpenSource IDE with debugger capabilities of PyCharm

No IDE recommendations, please!

There are many threads regarding that, so please search around, OP.

As for template debugging, this is currently a limitation in Django itself AFAIK, but efforts are being made to improve the situation.

Sincerely,
Andre Terra

-- Sent from my phone, please excuse any typos. --

On May 31, 2012 4:07 AM, "Houmie" <houmie@gmail.com> wrote:
Hi,

I have a question to the seasoned Django developers, I am relatively
new to Django and have been developing on Aptana Studio 3.0 since one
month.  While I think its a great free product, it seems debugging is
only limited to url.py and views.py. Beyond that there is no way to
set a break point in a template.

I just watched a video of pycharm and it seems pycharm is able to do
it.

I was wondering if I have setup Aptana incorrectly, and it would
support template debugging as well.

Otherwise is there any other open source django IDE you would
recommend that could debug templates?

Many thanks,
Houman

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

Re: Admin Inline empty extra - how to access parent form model ID?



On Wednesday, April 28, 2010 2:55:26 PM UTC+2, Daniel Roseman wrote:

The inline formset itself (rather than its forms) has an "instance"
attribute which refers to the instance of the parent form.

Sorry to bring back a two-years old post, but is there still a way to do this in django 1.4 ?
I'm exploring the BaseInlineFormset object but there's no "instance" attribute anymore

--
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/-/SHROXpngD-sJ.
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.

Re: Webservice return pdf

On 28/05/2012 9:51, Madhu wrote:
> Hi! all
> I create client & through client i call the web service.
> which returns pdf file, i want to stored that file directly.
> I use this
> response['Content-Disposition'] = 'attachment; filename= 'demo.pdf'
> but it will ask the user to store the file, but i want to store it automatically on server.
> can anybody please suggest me, how it should be done?
>
> Thanks

If you use response in the way you do, it will indeed ask to store the file.
As you seem to be able to present the pdf file, I don't see why you can't write the file
to a media directory?
You can then serve up these files directly or via a model.

It's not actually clear what you want to accomplish exactely.

Cheers,
Benedict


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

OpenSource IDE with debugger capabilities of PyCharm

Hi,

I have a question to the seasoned Django developers, I am relatively
new to Django and have been developing on Aptana Studio 3.0 since one
month. While I think its a great free product, it seems debugging is
only limited to url.py and views.py. Beyond that there is no way to
set a break point in a template.

I just watched a video of pycharm and it seems pycharm is able to do
it.

I was wondering if I have setup Aptana incorrectly, and it would
support template debugging as well.

Otherwise is there any other open source django IDE you would
recommend that could debug templates?

Many thanks,
Houman

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

Wednesday, May 30, 2012

Re: Django ModelForm user best practices

Good point. You can display the value but again.. you need to make sure it's a proper (not changed via post) value (clean() / save())

W dniu środa, 30 maja 2012 22:25:35 UTC+2 użytkownik Alexandr Aibulatov napisał:
For example on second method i can change post, board id's via html,
and write to board where i can be banned.
I think we shoudn't override standart methods if we con don't override
them(this about third method)


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

sqlall fails silently

hi
i defined three models and put them in /appname/models/ a.py, b.py,
c.py. and a __init__.py in which i import all classes defined inside
a.py/b.py/c.py.

when i try to do a ./manage.py sqll appname at prompt , it simply
passes of without any output.
what could be possibly done to debug it .. i had put the appname in
installed_apps, other app respond to sqlall printing related mysql
queries .
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Is Django Right for Me?

On Wed, 2012-05-30 at 12:01 -0400, Dennis Lee Bieber wrote:
> > other activities. The supervisor goes to the villages with netbooks.
> If
> > there is connectivity, he enters the data directly to the server on
> the
> > internet. If not, he has a local copy of the site running on his
> netbook
> > with a local copy of the database, synced before he leaves his
> office.
> > So he enters the data on that and later syncs it with the server. It
> is
> > not rocket science to write the scripts for syncing.
>
> If there is only one "supervisor" doing this, it may not be
> difficult...
>
>

that is the use case of the OP - and I do not see a big problem if
multiple people do it. Yet to test it out in practice. After all that is
what a dvcs does.
--
regards
Kenneth Gonsalves

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

Re: Python IDLE

On Thu, 2012-05-31 at 00:13 +1000, Mario Gudelj wrote:
> It's not free but they have a 30 day trial period

if you have an active open source project they will give you a free
license
--
regards
Kenneth Gonsalves

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

Re: Tough finding a form with dynamic fields out there

Daniel has point out the issue, but have a look at this speech from Django Con last year http://blip.tv/djangocon/advanced-django-form-usage-5573287. It has some great stuff in there.

-m

On 31 May 2012 06:14, Daniel Roseman <daniel@roseman.org.uk> wrote:
So, compare this:


    def __init__(self, mailboxes, *args, **kwargs):

 with how you're calling it:
 
form = MboxReg(request.POST, int(mailboxes))


and you should see why you're getting this: 
 
Error:
Exception Value:
int() argument must be a string or a number, not 'QueryDict'
On the
  •         for i in range(int(mailboxes)):
  • -- Mike


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

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

    404 message

    Am I supposed to see a 404 message upon completing this section of the
    tutorial? https://docs.djangoproject.com/en/1.4/intro/tutorial03/

    Sorry for the brevity as I'm trying to make the question concise.
    Thanks in advance!

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

    Re: Checkbox becomes combox ... why ?

    Thanks, but not main problems.
    Even if I remove "maybe" items,
    same incorrect outputs.

    Dennis Lee Bieber於 2012年5月31日星期四UTC+8上午12時09分44秒寫道:
    On Wed, 30 May 2012 02:24:53 -0700 (PDT), yillkid <yillkid@gmail.com>
    declaimed the following in gmane.comp.python.django.user:

    >
    > Filed "game_type" is a check box widget, BUT when I render the register
    > page,
    > It doesn't render to a checkbot but a combobox.
    > I don't why, thanks for reading my problem.

            Off-hand... Checkboxes are two-state items: On/Off (Yes/No; 1/0;
    checked/unchecked). BUT you are providing a three-state value for it --
    how is a checkbox supposed to render "Maybe"?
    --
            Wulfraed                 Dennis Lee Bieber         AF6VN
            wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/  

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

    Re: A signal, or equivalent, for when all apps are loaded?

    On Wed, May 30, 2012 at 9:59 PM, Bill Freeman <ke1g.nh@gmail.com> wrote:
    > On Tue, May 29, 2012 at 7:35 PM, Russell Keith-Magee
    > <russell@keith-magee.com> wrote:
    >> On Wed, May 30, 2012 at 4:42 AM, Bill Freeman <ke1g.nh@gmail.com> wrote:
    >>> I continue to struggle with occasional circular import problems
    >>> (caused by a combination of haystack, filebrowser, and a model which
    >>> both has a search_indexes.py and a model that has a filebrowser
    >>> field).
    >>>
    >>> I had thought that I had patched the issue by importing haystack in my
    >>> root urlconf (the problem doesn't happen under the development server
    >>> because it "validates models" early, but the import order was
    >>> different in production).  But: 1, I kept having to add "import
    >>> haystack" to my management commands; and 2, it still occasionally
    >>> fails on restart (a timing hazard of some kind).
    >>>
    >>> It strikes me that one fix would be to defer haystack's scan of the
    >>> INSTALLED_APPS until all the apps have been loaded.  But when is that?
    >>>  I can ask django.db.models.loading.app_cache_ready(), but it will say
    >>> False when haystack (or its models.py, which it has, despite not
    >>> having any models) is being imported (since the list of apps being
    >>> cached can't be finished until haystack.models import has finished).
    >>> So when could I run it again?  It would be nice to register for an
    >>> "apps are loaded" signal, but I don't see on in the docs, and there is
    >>> no evidence of sending one in django.db.models.loading.AppCache.
    >>>
    >>> Is there a right way to get something called after all the models have
    >>> been imported?  (Django 1.3)
    >>
    >> Unfortunately, there isn't. This is a long standing problem, and one
    >> that the app-refactor was looking into; however, that effort hasn't
    >> come to fruition. Django's startup sequence is an area where some work
    >> is required. The closest thing to a "signal" you're going to get is to
    >> hook into the URL configuration, in the same way the admin
    >> registration process does -- but it looks like you've tried that and
    >> haven't had any luck.
    >>
    >> One trick that I'm aware of that *might* work in your case is to force
    >> the validation code to run in your production stack -- for example, as
    >> a call in your WSGI container. From a functional perspective, this is
    >> an expensive no-op. The validation won't ever return a different
    >> result, which is why Django's WSGI handler doesn't call validate.
    >> However, the process of validation *does* cause the startup sequence
    >> to be a little more predictable, because the validation mechanism
    >> imports *all* your app modules in your project in a predictable order.
    >> If your problem is being caused by an unpredictable import order,
    >> forcing a specific import order may work around your problem (or at
    >> least make the side effects more predictable, and match the behaviour
    >> of the development server).
    >>
    >> Yours
    >> Russ Magee %-)
    >
    > Thanks Russ.
    >
    > I guess that I could just try importing django.db.models in my wsgi
    > file (in turn imports django.db.models.loading, which initializes the
    > AppCache) as a validation equivalent?

    I mentioned the validation thing because I know that it works. I'd
    have to check the models import to make sure it has exactly the same
    side effects, but it stands to reason that it might.

    Yours,
    Russ Magee %-)

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

    Re: Foreign Key Chicken/Egg Inline Fu

    Thanks Kurtis!

    That is helpful.

    -Patrick

    On May 30, 1:14 pm, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
    > I just checked on my own code that does something in a different
    > context but kinda performs the same check. I thought I'd share it with
    > you in case it helps out at all.
    >
    >     def clean_title(self):
    >
    >         # Grab the data to verify this Title is unique to this user.
    >         title = self.cleaned_data['title']
    >         owner = self.request.user
    >         slug = slugify(title)
    >
    >         # Grab all user pages query for validation
    >         user_pages = AbstractPage.objects.filter(owner = owner)
    >         user_pages = user_pages.exclude(pk = self.instance.pk)
    >
    >         # Validate Uniqueness
    >         if user_pages.filter(title = title).exists():
    >             raise ValidationError("The page title must be unique. It appears "
    >                                   + "you already have a page with this title.")
    >         elif user_pages.filter(slug = slug).exists():
    >             raise ValidationError("It appears that you're trying to use two "
    >                                   + " pages with titles that are too similar.")
    >         else: return title
    >
    > Of course, you'd want to 'clean' the Captain boolean field and make
    > sure that no other player in the same team is a captain before
    > allowing it to pass. Different context, but hopefully this approach
    > can help.
    >
    > On Wed, May 30, 2012 at 4:05 PM, Kurtis Mullins
    >
    >
    >
    >
    >
    >
    >
    > <kurtis.mull...@gmail.com> wrote:
    > > Sorry, I completely mis-read the last part of your problem. You
    > > already thought about the same solution, haha. You might be able to
    > > modify the Player model's clean (or save) method to prohibit any Team
    > > from having more than one team captain. However, I'd probably just
    > > check it in the Form you're using (outside of Admin)
    >
    > > On Wed, May 30, 2012 at 4:02 PM, Kurtis Mullins
    > > <kurtis.mull...@gmail.com> wrote:
    > >> Unless a player can play for multiple teams (which I'm doubting since
    > >> Team is a ForeignKey for a Player), why not remove that 'captain'
    > >> attribute from your Team and put it into your Player model as a
    > >> boolean field? You could create a ModelManager or class-level model
    > >> method to grab the associated team caption if you want to access it
    > >> easily. Otherwise, it's just a matter of:
    >
    > >> Team.objects.get('team_name').player_set.filter(captain=True) # Or
    > >> something along those lines...
    >
    > >> Just an idea anyways :) Good luck!
    >
    > >> On Wed, May 30, 2012 at 2:15 PM, Patrick Gavin <wezel...@gmail.com> wrote:
    > >>> Hi-
    >
    > >>> I'm new to Django, but so far I think it is the bee's knees.
    >
    > >>> I could use some insight into a problem I'm working on.
    >
    > >>> Given the following...
    >
    > >>> ---------------------------------
    > >>> # models.py
    >
    > >>> from django.db import models
    >
    > >>> class Team(models.Model):
    > >>>    name = models.CharField(max_length=30)
    >
    > >>>    # captain is a player- but there can only be one captain per team.
    > >>>    # null and blank are true to allow the team to be saved despite
    > >>> not having a captain
    > >>>    captain = models.ForeignKey('Player', related_name='team_captain',
    > >>> null=True, blank=True)
    >
    > >>>    def __unicode__(self):
    > >>>        return u'{0}'.format(self.name)
    >
    > >>> class Player(models.Model):
    > >>>    first_name = models.CharField(max_length=20)
    > >>>    last_name = models.CharField(max_length=30)
    > >>>    team = models.ForeignKey('Team')
    >
    > >>>    def __unicode__(self):
    > >>>        return u'{0} {1}'.format(self.first_name, self.last_name)
    >
    > >>> # admin.py
    >
    > >>> from league.models import *
    > >>> from django.contrib import admin
    >
    > >>> class PlayerInline(admin.TabularInline):
    > >>>    model = Player
    > >>>    extra = 8
    >
    > >>> class TeamAdmin(admin.ModelAdmin):
    > >>>    inlines = [PlayerInline]
    > >>>    list_display = ('name', 'captain')
    >
    > >>> ---------------------------------
    >
    > >>> As is, when I create a new team in the admin interface I can add the
    > >>> players inline, but I have to leave the team captain blank, save the
    > >>> team, and then go back and change the team and set the captain to one
    > >>> of the players added previously. This is kind of a drag though.
    >
    > >>> Is there a way that I can make the team captain be automatically set
    > >>> to the first player entered inline when the team is saved the first
    > >>> time?
    >
    > >>> I 've thought about adding a boolean field to the Player model called
    > >>> "is_captain", but I want to enforce only one captain per team. If I
    > >>> were to go this route, is there a way I could make the is_captain
    > >>> field default to True for the first inline entry but false for the
    > >>> rest?
    >
    > >>> Thanks,
    >
    > >>> -Patrick
    >
    > >>> --
    > >>> 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 athttp://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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

    Re: Adding values to formdata of ModelForm before saving

    Yes, it is possible:

    obj = form.save(commit=False)
    obj.in_calender-id = kalender
    obj.save()


    On Wed, May 30, 2012 at 2:56 PM, Schmidtchen Schleicher <spiollinux@googlemail.com> wrote:
    Is it possible to put missing data into the data of a form before calling form.save() ?
    I want to add the calendar-id (calid/in_calendar) before saving to the model.

     http://susepaste.org/23451355

    I tried adding it after instantiating the form with form.in_calendar_id = kalender but it didn't work
    I don't want to use hidden fields because manipulating them is easy

    Maybe https://groups.google.com/forum/?fromgroups#!topic/django-users/F5yHH-G5QLM describes how to solve it but I didn't understand it.

    PS: If you find very ugly code please correct me -- I'm a beginner

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



    --
    Jonathan D. Baker
    Developer
    http://jonathandbaker.com

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

    Adding values to formdata of ModelForm before saving

    Is it possible to put missing data into the data of a form before calling form.save() ?
    I want to add the calendar-id (calid/in_calendar) before saving to the model.

     http://susepaste.org/23451355

    I tried adding it after instantiating the form with form.in_calendar_id = kalender but it didn't work
    I don't want to use hidden fields because manipulating them is easy

    Maybe https://groups.google.com/forum/?fromgroups#!topic/django-users/F5yHH-G5QLM describes how to solve it but I didn't understand it.

    PS: If you find very ugly code please correct me -- I'm a beginner

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

    Re: Django ModelForm user best practices

    For example on second method i can change post, board id's via html,
    and write to board where i can be banned.
    I think we shoudn't override standart methods if we con don't override
    them(this about third method)

    P.S. sorry for my terrible english.

    2012/5/31 Kurtis Mullins <kurtis.mullins@gmail.com>:
    >> On second method some experience users can
    >> override hidden data
    >
    > For the second method, you'd just use -- class Meta: fields =
    > ('board', 'post', 'name') to prohbit anyone from trying to override
    > the 'user', if that's what you're talking about.
    >
    >> And it's a bad idea to
    >> override __init__ and save method in my humble opinion/
    >
    > What better purpose for the save() method than to save? :) I'm not
    > sure why it's a bad idea to override __init__, though. Feel free to
    > elaborate. I'm always open for new information!
    >
    > --
    > 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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

    Re: Python IDLE

    Back to the original question,

    Did you try running "python manage.py runserver" from the command
    prompt? As far as changing those icons back to Python, I believe you
    have to change your 'Default Program'. I'm not sure which version of
    Widnows you're using (or even how to do it in Windows, I'm running
    Linux) but I'm sure you could use Google (or duckduckgo.com) for a
    quick answer there.

    If you still can't run 'runserver', try using your command prompt to
    do something along the following (your paths may/will be different)

    c:\python27\bin\python.exe c:\my_directory\my_project\manage.py runserver

    Basically, you're just telling the Python interpreter (python.exe or
    python27.exe) to execute the "manage.py" file. Also, please note:
    Python Versions > 2.7.x (3+) will not work with Django at the moment.

    Good luck!

    On Mon, May 28, 2012 at 8:37 AM, coded kid <duffleboi911@gmail.com> wrote:
    > I'm in a big mess now, I've lost my projects due to this errror. I'm
    > on windows, This is how I encounter the problem; I try to edit my
    > settings.py in IDLE. After right clicking on the files, I choose open
    > program with these default file. I choose idle window bat file, and I
    > clicked Ok. It didn't open, I try to run manage.py runserver on my
    > DOS. Not working, it will pop up the IDLE Shell and mange.py script by
    > displaying it in IDLE. It didn't run the server. The logo of my python
    > files have changed. How can I revert it back to open with IDLE? And
    > use it as default for my python script?
    >
    > --
    > 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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

    Re: Foreign Key Chicken/Egg Inline Fu

    I just checked on my own code that does something in a different
    context but kinda performs the same check. I thought I'd share it with
    you in case it helps out at all.

    def clean_title(self):

    # Grab the data to verify this Title is unique to this user.
    title = self.cleaned_data['title']
    owner = self.request.user
    slug = slugify(title)

    # Grab all user pages query for validation
    user_pages = AbstractPage.objects.filter(owner = owner)
    user_pages = user_pages.exclude(pk = self.instance.pk)

    # Validate Uniqueness
    if user_pages.filter(title = title).exists():
    raise ValidationError("The page title must be unique. It appears "
    + "you already have a page with this title.")
    elif user_pages.filter(slug = slug).exists():
    raise ValidationError("It appears that you're trying to use two "
    + " pages with titles that are too similar.")
    else: return title

    Of course, you'd want to 'clean' the Captain boolean field and make
    sure that no other player in the same team is a captain before
    allowing it to pass. Different context, but hopefully this approach
    can help.

    On Wed, May 30, 2012 at 4:05 PM, Kurtis Mullins
    <kurtis.mullins@gmail.com> wrote:
    > Sorry, I completely mis-read the last part of your problem. You
    > already thought about the same solution, haha. You might be able to
    > modify the Player model's clean (or save) method to prohibit any Team
    > from having more than one team captain. However, I'd probably just
    > check it in the Form you're using (outside of Admin)
    >
    > On Wed, May 30, 2012 at 4:02 PM, Kurtis Mullins
    > <kurtis.mullins@gmail.com> wrote:
    >> Unless a player can play for multiple teams (which I'm doubting since
    >> Team is a ForeignKey for a Player), why not remove that 'captain'
    >> attribute from your Team and put it into your Player model as a
    >> boolean field? You could create a ModelManager or class-level model
    >> method to grab the associated team caption if you want to access it
    >> easily. Otherwise, it's just a matter of:
    >>
    >> Team.objects.get('team_name').player_set.filter(captain=True) # Or
    >> something along those lines...
    >>
    >> Just an idea anyways :) Good luck!
    >>
    >> On Wed, May 30, 2012 at 2:15 PM, Patrick Gavin <wezelboy@gmail.com> wrote:
    >>> Hi-
    >>>
    >>> I'm new to Django, but so far I think it is the bee's knees.
    >>>
    >>> I could use some insight into a problem I'm working on.
    >>>
    >>> Given the following...
    >>>
    >>> ---------------------------------
    >>> # models.py
    >>>
    >>> from django.db import models
    >>>
    >>> class Team(models.Model):
    >>>    name = models.CharField(max_length=30)
    >>>
    >>>    # captain is a player- but there can only be one captain per team.
    >>>    # null and blank are true to allow the team to be saved despite
    >>> not having a captain
    >>>    captain = models.ForeignKey('Player', related_name='team_captain',
    >>> null=True, blank=True)
    >>>
    >>>    def __unicode__(self):
    >>>        return u'{0}'.format(self.name)
    >>>
    >>> class Player(models.Model):
    >>>    first_name = models.CharField(max_length=20)
    >>>    last_name = models.CharField(max_length=30)
    >>>    team = models.ForeignKey('Team')
    >>>
    >>>    def __unicode__(self):
    >>>        return u'{0} {1}'.format(self.first_name, self.last_name)
    >>>
    >>>
    >>> # admin.py
    >>>
    >>> from league.models import *
    >>> from django.contrib import admin
    >>>
    >>> class PlayerInline(admin.TabularInline):
    >>>    model = Player
    >>>    extra = 8
    >>>
    >>> class TeamAdmin(admin.ModelAdmin):
    >>>    inlines = [PlayerInline]
    >>>    list_display = ('name', 'captain')
    >>>
    >>> ---------------------------------
    >>>
    >>> As is, when I create a new team in the admin interface I can add the
    >>> players inline, but I have to leave the team captain blank, save the
    >>> team, and then go back and change the team and set the captain to one
    >>> of the players added previously. This is kind of a drag though.
    >>>
    >>> Is there a way that I can make the team captain be automatically set
    >>> to the first player entered inline when the team is saved the first
    >>> time?
    >>>
    >>> I 've thought about adding a boolean field to the Player model called
    >>> "is_captain", but I want to enforce only one captain per team. If I
    >>> were to go this route, is there a way I could make the is_captain
    >>> field default to True for the first inline entry but false for the
    >>> rest?
    >>>
    >>> Thanks,
    >>>
    >>> -Patrick
    >>>
    >>> --
    >>> 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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

    Re: Tough finding a form with dynamic fields out there

    So, compare this:

        def __init__(self, mailboxes, *args, **kwargs):

     with how you're calling it:
     
    form = MboxReg(request.POST, int(mailboxes))


    and you should see why you're getting this: 
     
    Error:
    Exception Value:
    int() argument must be a string or a number, not 'QueryDict'
    On the
  •         for i in range(int(mailboxes)):
  • -- Mike


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

    Re: Django ModelForm user best practices

    > On second method some experience users can
    > override hidden data

    For the second method, you'd just use -- class Meta: fields =
    ('board', 'post', 'name') to prohbit anyone from trying to override
    the 'user', if that's what you're talking about.

    > And it's a bad idea to
    > override __init__ and save method in my humble opinion/

    What better purpose for the save() method than to save? :) I'm not
    sure why it's a bad idea to override __init__, though. Feel free to
    elaborate. I'm always open for new information!

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

    Re: Foreign Key Chicken/Egg Inline Fu

    Sorry, I completely mis-read the last part of your problem. You
    already thought about the same solution, haha. You might be able to
    modify the Player model's clean (or save) method to prohibit any Team
    from having more than one team captain. However, I'd probably just
    check it in the Form you're using (outside of Admin)

    On Wed, May 30, 2012 at 4:02 PM, Kurtis Mullins
    <kurtis.mullins@gmail.com> wrote:
    > Unless a player can play for multiple teams (which I'm doubting since
    > Team is a ForeignKey for a Player), why not remove that 'captain'
    > attribute from your Team and put it into your Player model as a
    > boolean field? You could create a ModelManager or class-level model
    > method to grab the associated team caption if you want to access it
    > easily. Otherwise, it's just a matter of:
    >
    > Team.objects.get('team_name').player_set.filter(captain=True) # Or
    > something along those lines...
    >
    > Just an idea anyways :) Good luck!
    >
    > On Wed, May 30, 2012 at 2:15 PM, Patrick Gavin <wezelboy@gmail.com> wrote:
    >> Hi-
    >>
    >> I'm new to Django, but so far I think it is the bee's knees.
    >>
    >> I could use some insight into a problem I'm working on.
    >>
    >> Given the following...
    >>
    >> ---------------------------------
    >> # models.py
    >>
    >> from django.db import models
    >>
    >> class Team(models.Model):
    >>    name = models.CharField(max_length=30)
    >>
    >>    # captain is a player- but there can only be one captain per team.
    >>    # null and blank are true to allow the team to be saved despite
    >> not having a captain
    >>    captain = models.ForeignKey('Player', related_name='team_captain',
    >> null=True, blank=True)
    >>
    >>    def __unicode__(self):
    >>        return u'{0}'.format(self.name)
    >>
    >> class Player(models.Model):
    >>    first_name = models.CharField(max_length=20)
    >>    last_name = models.CharField(max_length=30)
    >>    team = models.ForeignKey('Team')
    >>
    >>    def __unicode__(self):
    >>        return u'{0} {1}'.format(self.first_name, self.last_name)
    >>
    >>
    >> # admin.py
    >>
    >> from league.models import *
    >> from django.contrib import admin
    >>
    >> class PlayerInline(admin.TabularInline):
    >>    model = Player
    >>    extra = 8
    >>
    >> class TeamAdmin(admin.ModelAdmin):
    >>    inlines = [PlayerInline]
    >>    list_display = ('name', 'captain')
    >>
    >> ---------------------------------
    >>
    >> As is, when I create a new team in the admin interface I can add the
    >> players inline, but I have to leave the team captain blank, save the
    >> team, and then go back and change the team and set the captain to one
    >> of the players added previously. This is kind of a drag though.
    >>
    >> Is there a way that I can make the team captain be automatically set
    >> to the first player entered inline when the team is saved the first
    >> time?
    >>
    >> I 've thought about adding a boolean field to the Player model called
    >> "is_captain", but I want to enforce only one captain per team. If I
    >> were to go this route, is there a way I could make the is_captain
    >> field default to True for the first inline entry but false for the
    >> rest?
    >>
    >> Thanks,
    >>
    >> -Patrick
    >>
    >> --
    >> 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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.