Tuesday, July 31, 2012

Re: Issue Deploying Django

On Tue, 2012-07-31 at 20:52 -0700, JJ Zolper wrote:
> Do I need to go through and install the python like adapters is that
> what it's complaining about? I don't think this has to do with my
> Django code on the server it's just a file missing right?

you need to install pycopg - and it is nothing to do with your code
--
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: form.errors is not a dictionary?

I too have the same problem. How did you fix it?

On Wednesday, April 6, 2011 2:13:48 AM UTC+5:30, Roy Smith wrote:
I'm using django-1.3 .  I have a view with the following code:

def item_create(request):
    if request.method == 'POST':
        form = ItemForm(request.POST)
        if form.is_valid():
            url = form.cleaned_data['url']
            item.save()
            return HttpResponseRedirect('/')
        else:
            print form.errors

when I submit the form, I expected that form.errors would print out as
a dict, as documented in http://docs.djangoproject.com/en/1.3/ref/forms/api/#using-forms-to-validate-data.
Instead, I'm getting a hunk of HTML:


Django version 1.3, using settings 'soco-site.settings'
Development server is running at http://0.0.0.0:7626/
Quit the server with CONTROL-C.
<ul class="errorlist"><li>date_added<ul class="errorlist"><li>This
field is required.</li></ul></li><li>user_id<ul
class="errorlist"><li>This field is required.</li></ul></li></ul>
[05/Apr/2011 16:36:32] "POST /item/create/ HTTP/1.1" 200 718

Is my understanding wrong, or is this a bug?

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

Issue Deploying Django

Hello all,

I've been working on trying to Deploy Django for the past day or so now. I see entire in the image in my ssh when trying to run:

./manage.py runfcgi protocol=fcgi

It says: "Error no module named psycopg2.extensions"

I didn't install any psycopg-python stuff because I knew that postgresql was already on my bluehost account.

Do I need to go through and install the python like adapters is that what it's complaining about? I don't think this has to do with my Django code on the server it's just a file missing right?

Thanks,

JJ


--
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/-/Di8so283hvsJ.
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: Error in Brand New Django 1.4.1 released Yesterday

Yesterday I did ...

pip install --upgrade django

... and it happily upgraded mine to 1.4.1

Mike

On 1/08/2012 9:46am, Dennis Lee Bieber wrote:
> On Tue, 31 Jul 2012 16:06:20 -0700 (PDT), JJ Zolper
> <codingatmt@gmail.com> declaimed the following in
> gmane.comp.python.django.user:
>
>> Nope. Not Python 1.4. Django 1.4.
>>
>> http://pypi.python.org/pypi/Django/1.4#downloads
>>
> Intriguing... When I did my search python.org routed me to the
> Django server itself...
>

--
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-allauth and signup or login via twitter?

I am trying to work with django-allauth. I followed the instructions at github page and done following:

1. Added allauth urls into urls.py

urlpatterns += patterns ('',
    url('^accounts/', include('allauth.urls')),
    url('^accounts/profile/$', ProfileView.as_view(), name='ProfileView'),
    url('^login/$', login, name='account_login'),
    url('^logout/$', logout, name='account_logout'),
    url('^login/cancelled/$', login_cancelled, name='socialaccount_login_cancelled'),
    url('^login/error/$', login_error, name='socialaccount_login_error'),
)

2. Updated TEMPLATE_CONTEXT_DIRS, TEMPLATE_CONTEXT_PROCESSORS, AUTHENTICATION_BACKENDS and INSTALLED_APPS. Also added ACCOUNT_AUTHENTICATION_METHOD = "username_email"

3. Added Key and Secret for twitter in the Social apps table.

4. Copied django-allauth templates to my app's directory and modified it. I can see all the templates working fine like /accounts/signup/ and /accounts/social/connections/.

Now, from connections or signup when I click Twitter link /accounts/twitter/login/ I ended up with the following error:

Social Network Login Failure
An error occured while attempting to login via your social network account.

Am I missing something? Did anybody ever try to login or sign up using twitter? I tried to search for all solution on the web but was not able to find any. If this thing doesn't work then I would like to try django-social-auth.

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/-/t2PaUkNqN4QJ.
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 more data to Generic Views

On Wed, Aug 1, 2012 at 8:45 AM, Lachlan Musicman <datakid@gmail.com> wrote:
On Wed, Aug 1, 2012 at 12:43 AM, Melvyn Sopacua <m.r.sopacua@gmail.com> wrote:
On 31-7-2012 6:17, Lachlan Musicman wrote:

> I have Person, Certificate, Job and Compensation objects. The last three
> all
> have an FK (or M2M) back to a (or some) Person(s).
>

You don't need any of these. In your template, simply call:
{{ person.certificate_set.fieldname }}

I will try using person.vacancy_set.all now ...

Ok - this only works for FK relationships, not for M2M relationships?

cheers
L.  

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

Detecting browser type after login

I've only been working with django for 6 months, and I'm not really
clear on how the login process works.

I have a client that has a login screen created by a template. It has
a submit button with:

<form id="login" action="/accounts/login/" method="POST">

In their urls file they have:

(r'^accounts/login/$', login)

In their views file they call login(request)

What they want is, after the user has successfully logged in, I need
to detect which browser they are using, and depending on which it is,
potentially pop up a dialog box. I can't figure out where that code
would live. I'm not asking how to detect the browser type, but rather,
where that javascript code would go, and how I would cause it to get
invoked after the login.

TIA!
-larry

--
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: Error in Brand New Django 1.4.1 released Yesterday

On Tue, 31 Jul 2012 16:06:20 -0700 (PDT), JJ Zolper
<codingatmt@gmail.com> declaimed the following in
gmane.comp.python.django.user:

> Nope. Not Python 1.4. Django 1.4.
>
> http://pypi.python.org/pypi/Django/1.4#downloads
>
Intriguing... When I did my search python.org routed me to the
Django server itself...
--
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 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: Error in Brand New Django 1.4.1 released Yesterday

Nope. Not Python 1.4. Django 1.4.

http://pypi.python.org/pypi/Django/1.4#downloads

I ran the following commands in the python interpreter and saw the following:

>>> import django
>>> print django.get_version()
1.4

I'm good to go. Not sure if the 1.4.1 file off of djangoproject.com is in the right shape so I went with what I knew, 1.4.

Cheers,

JJ

--
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/-/PprM-ZVPHDsJ.
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: returning a zip file for download

On Tue, Jul 31, 2012 at 5:03 PM, Tomas Neme <lacrymology@gmail.com> wrote:
> The weird thing is that I'm getting just a pdf file (ok, I'm testing with a
> single file, so I don't know if that's the problem)

shoot in the dark: maybe the browser is interpreting the zipped PDF as
a zip-encoded response, and decoding it for you.

the right mimetype and content-disposition (as suggested by Nikolas) should help

--
Javier

--
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: Problem with order_by on one record only

Just to update this in case anyone else has a similar problem...
I used a DecimalField where the database had a Float value, so I switched it to a FloatField in my models and it fixed the problem.  Of course, some precision may be lost in doing this, but considering the values I'm reading are actually fixed point to begin with, I don't really mind as the precision was set to a certain amount before it ever hit my database.

Hope this helps someone else down the line.

On Friday, June 15, 2012 5:42:28 PM UTC-4, Alex Umrysh wrote:
I'm having a strange error on an object query when I try to do negative order_by. This is on an Oracle 11 database with Django 1.4
it looks something like:

MyModel.objects.filter(pk=N).order_by('-datetime')[:5]

This gives me valid data for all values of N in the database except for one specific record.
This one record works fine when the order_by is on 'datetime', but '-datetime' doesn't work.  using .latest('datetime') appears to do the same thing (under the hood), so there's no difference in the behavior there.

I'm not sure what the issue is with this specific object, but it does use more columns than the rest of the objects in the database.

I have looked at the datetime objects, and they all appear to be good.
I added some additional model fields based on the changes my DBA made to this table, but I'm not certain why this would cause this one specific object to return nothing where others do, as the data appears good.
any ideas where to look?
I would provide more code but it's of a confidential nature so I'll have to scrub any names before I post the models, so I'm hoping someone has an idea or hunch before I have to do that.

Thanks, and sorry for not posting much code.

--
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/-/24rdpeCNuNIJ.
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: MySQL total overheat (somewhat complex database)

Hello, I forgot to mention, that this query is generated automatically by Django admin when opening this model admin page.


Dne pondělí, 30. července 2012 14:53:10 UTC+2 Cal Leeming [Simplicity Media Ltd] napsal(a):
Could you provide us with the models.py for this table? Just the model definitions will suffice.

Can you also provide the snippet of Python code which is generating this SQL

Cal

On Sat, Jul 28, 2012 at 7:44 PM, lubos <lubosboucek@gmail.com> wrote:
Hello,

I have a quite sophisticated database with frequently interconnected tables and on the top level table, Django produces queries like this:

SELECT `data_schedule`.`id`, `data_schedule`.`process_id`, `data_schedule`.`hardware_id`, `data_schedule`.`task_id`, `data_schedule`.`start`, `data_schedule`.`times`, `data_schedule`.`done`, `data_process`.`id`, `data_process`.`string_id`, `data_process`.`operation_id`, `data_string`.`id`, `data_string`.`immutable`, `data_operation`.`id`, `data_operation`.`string_id`, T5.`id`, T5.`immutable`, `data_hardware`.`id`, `data_hardware`.`string_id`, `data_hardware`.`workspace_id`, `data_hardware`.`warmup`, T7.`id`, T7.`immutable`, `data_workspace`.`id`, `data_workspace`.`string_id`, T9.`id`, T9.`immutable`, `data_task`.`id`, `data_task`.`request_id`, `data_task`.`thread_id`, `data_task`.`amount`, `data_request`.`id`, `data_request`.`order_id`, `data_request`.`item_id`, `data_request`.`amount`, `data_order`.`id`, `data_order`.`string_id`, `data_order`.`subject_id`, `data_order`.`type`, `data_order`.`shipped`, `data_order`.`paid`, `data_order`.`end`, T13.`id`, T13.`immutable`, `data_subject`.`id`, `data_subject`.`string_id`, T15.`id`, T15.`immutable`, `data_item`.`id`, `data_item`.`string_id`, `data_item`.`measure_id`, `data_item`.`amount`, T17.`id`, T17.`immutable`, `data_measure`.`id`, `data_measure`.`string_id`, T19.`id`, T19.`immutable`, `data_thread`.`id`, `data_thread`.`string_id`, T21.`id`, T21.`immutable` FROM `data_schedule` INNER JOIN `data_process` ON (`data_schedule`.`process_id` = `data_process`.`id`) INNER JOIN `data_string` ON (`data_process`.`string_id` = `data_string`.`id`) INNER JOIN `data_operation` ON (`data_process`.`operation_id` = `data_operation`.`id`) INNER JOIN `data_string` T5 ON (`data_operation`.`string_id` = T5.`id`) INNER JOIN `data_hardware` ON (`data_schedule`.`hardware_id` = `data_hardware`.`id`) INNER JOIN `data_string` T7 ON (`data_hardware`.`string_id` = T7.`id`) INNER JOIN `data_workspace` ON (`data_hardware`.`workspace_id` = `data_workspace`.`id`) INNER JOIN `data_string` T9 ON (`data_workspace`.`string_id` = T9.`id`) INNER JOIN `data_task` ON (`data_schedule`.`task_id` = `data_task`.`id`) INNER JOIN `data_request` ON (`data_task`.`request_id` = `data_request`.`id`) INNER JOIN `data_order` ON (`data_request`.`order_id` = `data_order`.`id`) INNER JOIN `data_string` T13 ON (`data_order`.`string_id` = T13.`id`) INNER JOIN `data_subject` ON (`data_order`.`subject_id` = `data_subject`.`id`) INNER JOIN `data_string` T15 ON (`data_subject`.`string_id` = T15.`id`) INNER JOIN `data_item` ON (`data_request`.`item_id` = `data_item`.`id`) INNER JOIN `data_string` T17 ON (`data_item`.`string_id` = T17.`id`) INNER JOIN `data_measure` ON (`data_item`.`measure_id` = `data_measure`.`id`) INNER JOIN `data_string` T19 ON (`data_measure`.`string_id` = T19.`id`) INNER JOIN `data_thread` ON (`data_task`.`thread_id` = `data_thread`.`id`) INNER JOIN `data_string` T21 ON (`data_thread`.`string_id` = T21.`id`) ORDER BY `data_schedule`.`id` ASC

MySQL, however, isn't able to process it and after few minutes it holds all processor performance.

I would be glad for any idea.

Lubos

--
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/-/xwjqe16wlNYJ.
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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9nJb0sEyDEUJ.
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: Weird test-behaviour in combination with localization

Ok, so I fixed my problem, but i have the feelings this cant really be a longterm solution ^^. If i create my own testsuite and skip all django-apps, the tests pass, if i comment them in, they wont run (With the above error). is there a possibility django changes the language-settings somehow within its own tests, which affect my other tests?


On Tuesday, July 31, 2012 9:21:28 PM UTC+2, Andre Schemschat wrote:
Hey together,
I was just writing some tests for my views and i stumbled upon a localization error, which i cant figure out :/
I have a test that checks the form-validation returnes the correct errors-messages for specific input data. Basicly what i feed to the view are the field-names and their values and in return i get a json-string with the error-messages for the fields.
This works fine, if i just run the tests for that specific view. (Result is something like {'fielda':'Dieses Feld ist zwingend erforderlich.'}, where 'Dieses Feld ist zwingend erforderlich.'=>'This field is required' in german). 
Now, if i run all tests, not just for that specific view, the test fails, because the view returnes {'fielda':'This field is required.'} instead of the german localization. I checked the settings.LANGUAGE_CODE-value in the view and in the test, in both cases it is de-de.
Any ideas, why my test is fine if it runs alone and fails when all tests of the project (including the django-ones) are run? Im fresh out of ideas and a little bit puzzled :D

Greetings & Thanks,
Andre

--
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/-/wK0WOFd9Es8J.
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: returning a zip file for download

I'm not sure why you're getting a PDF file back, but as for the filename, you can set it using the Content-Disposition header. E.g:

response = return HttpResponse(open(tmp[1]), mimetype="application/zip")
response['Content-Disposition'] = 'attachment; filename="whatever.zip'
return response


_Nik


On 7/31/2012 3:03 PM, Tomas Neme wrote:

Down here's the code in which I'm creating a zip file with a bunch of pdf labels, and returning it on the HttpResponse for the user to DL it.

The weird thing is that I'm getting just a pdf file (ok, I'm testing with a single file, so I don't know if that's the problem) and I can't set the downloaded filename to anything (it's always "download")

Can someone see what I'm doing wrong?

        files = []
        for detail in queryset:
            for parcel in detail.parceldescription_set.select_related().all():
                shipment = parcel.shipment
                if not shipment.label:
                    try:
                        shipment.download_label(args['username'], args['password'])
                    except Shipment.Wait:
                        self.message_user(_("Failed downloading label for "
                                            "shipment {id} because the "
                                            "Canada Post server is busy, "
                                            "please wait a couple of minutes "
                                            "and try again").format(
                            id=shipment.id))
                files.append(shipment.label.file)

        tmp = tempfile.mkstemp(suffix=".zip")
        tf = zipfile.ZipFile(tmp[1], mode="w")
        for file in files:
            filename = os.path.basename(file.name)
            tf.write(file.name, filename)
        tf.close()

        return HttpResponse(open(tmp[1]), mimetype="application/zip")


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

combobox prepopulated to only related objects to "self"

Hi everyone

i have this model

GROUP and Product


product has a group field thath is foreignkey to GROUP.


and Group has foreignKey to Product to select primary product.

so i want to have a group with many products and one is the "primary product".


so...i could do this by select inline products with "trough" and search an intermediary Model (boolean field).

but it let me select  more than one promary,


the solution is the model this way:.

product has a group field thath is foreignkey to GROUP.


and Group has foreignKey to Product to select primary product.

so i want to have a group with many products and one is the "primary product".

but the primaryproduct field in group will be prepopulated with only the related products to this group.


how i prepopulate the select(combobox) with the reverse query ?






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

returning a zip file for download


Down here's the code in which I'm creating a zip file with a bunch of pdf labels, and returning it on the HttpResponse for the user to DL it.

The weird thing is that I'm getting just a pdf file (ok, I'm testing with a single file, so I don't know if that's the problem) and I can't set the downloaded filename to anything (it's always "download")

Can someone see what I'm doing wrong?

        files = []
        for detail in queryset:
            for parcel in detail.parceldescription_set.select_related().all():
                shipment = parcel.shipment
                if not shipment.label:
                    try:
                        shipment.download_label(args['username'], args['password'])
                    except Shipment.Wait:
                        self.message_user(_("Failed downloading label for "
                                            "shipment {id} because the "
                                            "Canada Post server is busy, "
                                            "please wait a couple of minutes "
                                            "and try again").format(
                            id=shipment.id))
                files.append(shipment.label.file)

        tmp = tempfile.mkstemp(suffix=".zip")
        tf = zipfile.ZipFile(tmp[1], mode="w")
        for file in files:
            filename = os.path.basename(file.name)
            tf.write(file.name, filename)
        tf.close()

        return HttpResponse(open(tmp[1]), mimetype="application/zip")


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

Re: No timezone support for TimeField?

On 7/31/12 1:34 PM, Tejinder Singh wrote:
Django 1.4 does not store aware times for TimeField, it only does for DateTimeField. Its really annoying, as python datetime.time object does support TZINFO just like datetime.datetime objects. I wonder if it is a bug? Btw i have tested it on postgres 9.1 database server
Time zones have no meaning without a date attached, so having a time zone travel with a time of day does not lead to something useful. fwiw I implemented the Postgres date/time types back in the day...

                           - Tom

Re: Adding more data to Generic Views

On Wed, Aug 1, 2012 at 12:43 AM, Melvyn Sopacua <m.r.sopacua@gmail.com> wrote:
On 31-7-2012 6:17, Lachlan Musicman wrote:

> I have Person, Certificate, Job and Compensation objects. The last three
> all
> have an FK (or M2M) back to a (or some) Person(s).
>

So reverse relations.

Yep, thanks - with Django I often find I have an idea in my head but don't know what to call it - and it's often surprising what the developers do call it, until it makes perfect sense . I'm still waiting for that eureka moment with reverse urls tbh - I have read the docs on those a dozen times, and just do not get why they are useful or when you would use them. I guess I need a local example.
 
>     def get_context_data(self,**kwargs):
>         #Call the base implementation first to get a context
>         context = super(PersonDetailView, self).get_context_data(**kwargs)
>         #Add in a querysets
>         context['job_list'] = Vacancy.complete.all()
>         context['certificate_list'] = Certificate.objects.all()
>         context['claim_list'] = Compensation.objects.all()

You don't need any of these. In your template, simply call:
{{ person.certificate_set.fieldname }}

Yes, I was doing that originally (when there was no Compensation objects), but I was struggling with only rendering when a set existed - for example, in my person_detail.html I was rendering from the wrong direction - via the non-Person object via "related name" fields on the FK.

        {% if person.jobs %}
        <h3>Jobs Applied For</h3>
        {% for job in person.jobs.all %}
        <p>
        <a href="{{ job.get_absolute_url }}">{{ job.title }}, <em>{{ job.organisation }}{% if job.division %}, {{ job.division }}{% endif %}</em></a>
        </p>
 
Which gives me the problem that I was *actually* trying to solve - how to only render "Jobs Applied For" - the reason for the if statement - if jobs have been applied for by that person. It didn't work. 

I will try using person.vacancy_set.all now ...

 
If you insist on having them available as you do above, they should be:
context['job_list'] = self.get_object().vacancy_set.all()
context['certificate_list'] = self.get_object().certificate_set.all()
context['claim_list'] = self.get_object().compensation_set.all()

Required reading: 
https://docs.djangoproject.com/en/1.4/ref/models/relations/

Also, skipping the tutorial is not recommended:
<https://docs.djangoproject.com/en/1.4/intro/tutorial03/#use-the-template-system>

I didn't, but I did only skim it, since I've done it before.

> Of course, the other thing that I can't help but thinking is that at this
> point, the non-generic-view method of urls/views might be a simpler way to
> go. While Generic Views are quite versatile,  is there a point at which
> they are considered to restricting?

*too*
 
Not really. The only thing that bugs me about them is that adding extra
context requires sub-classing so you end up with a views.py that solely
consists of sub-classed generic views with 3 lines of get_context_data().

Ok, thanks. I'm still confused about the usefulness of subclassing, given that object_set exists? I presuming it's to have the actual objects in the context, not just a reference to them?

anyway, thanks for hte help
L.
 

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

No timezone support for TimeField?

Django 1.4 does not store aware times for TimeField, it only does for DateTimeField. Its really annoying, as python datetime.time object does support TZINFO just like datetime.datetime objects. I wonder if it is a bug? Btw i have tested it on postgres 9.1 database server

--
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/-/kiRgiOZiDDAJ.
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 more data to Generic Views

On Tue, Jul 31, 2012 at 11:15 PM, Karl Sutt <karl@sutt.ee> wrote:
So, in conclusion, Lachlan, you would want to do something like:

 def get_context_data(self,**kwargs):
        #Call the base implementation first to get a context
        context = super(PersonDetailView, self).get_context_data(**kwargs)
        #Add in a querysets
        context['job_list'] = Vacancy.complete.filter(person_id=self.kwargs[self.pk_url_kwarg])
        context['certificate_list'] = Certificate.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
        context['claim_list'] = Compensation.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
        return context

I have not tested this, but it gives you the idea. You'll want to filter the Vacancy, Certificate and Compensation objects by the person's ID. 

Great - thanks!

L, 

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

Weird test-behaviour in combination with localization

Hey together,
I was just writing some tests for my views and i stumbled upon a localization error, which i cant figure out :/
I have a test that checks the form-validation returnes the correct errors-messages for specific input data. Basicly what i feed to the view are the field-names and their values and in return i get a json-string with the error-messages for the fields.
This works fine, if i just run the tests for that specific view. (Result is something like {'fielda':'Dieses Feld ist zwingend erforderlich.'}, where 'Dieses Feld ist zwingend erforderlich.'=>'This field is required' in german). 
Now, if i run all tests, not just for that specific view, the test fails, because the view returnes {'fielda':'This field is required.'} instead of the german localization. I checked the settings.LANGUAGE_CODE-value in the view and in the test, in both cases it is de-de.
Any ideas, why my test is fine if it runs alone and fails when all tests of the project (including the django-ones) are run? Im fresh out of ideas and a little bit puzzled :D

Greetings & Thanks,
Andre

--
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/-/WrS3xL3_SBUJ.
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: Working with a Custom, Dynamic Form (using BaseForm)

what is going on here:
    self.base_fields = fields_for_a(self.instance) ?



On Tue, Jul 31, 2012 at 8:14 PM, Nick_B <nickbewley@gmail.com> wrote:
Hi,

Have hit a huge roadblock trying to implement a custom, dynamic form into my django project. Although I am more familiar with using ModelForms, I need to use BaseForm to work with the structure I already have in place.

I have a dictionary of objects inside of my Model 'Photographer' that I am trying to pass into my form. The objects from 'Photographer' will be a drop down option for the user to select from, then will become part of an instance of another model 'A' after the user submits the form. I cannot figure out how to include the objects from 'Photographer' into my form, given the following form structure:

    class AForm(BaseForm):
        def __init__(self, data=None, files=None, instance=None, auto_id='id_%s',
                     prefix=None, initial=None, error_class=ErrorList,
                     label_suffix=':', empty_permitted=False):

            if not instance:
                raise NotImplementedError("Instance must be provided")

            self.instance = instance
            object_data = self.instance.fields_dict()
            self.declared_fields = SortedDict()
            self.base_fields = fields_for_a(self.instance)

            # if initial was provided, it should override the values from instance
            if initial is not None:
                object_data.update(initial)

            BaseForm.__init__(self, data, files, auto_id, prefix, object_data,
                              error_class, label_suffix, empty_permitted)

            cleaned_data = self.cleaned_data

            # save fieldvalues for self.instance
            fields = field_list(self.instance)

            for field in fields:
                if field.enable_wysiwyg:
                    value = unicode(strip(cleaned_data[field.name]))
                else:
                    value = unicode(cleaned_data[field.name])

            return self.instance

For a more full representation of the problem in general, including all of the models and a lot of the view code, please see my stack overflow question: http://stackoverflow.com/questions/11548992/adding-values-to-complex-django-view

I cannot thank you enough for any advice given. I have been struggling with this issue for over a month, sadly. I appreciate any commentary.


Thank you!

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



--
Regards,
Anton Baklanov

--
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: Form validation using model data?

ahh okay,

then I simply create two model forms.

class CreateURLForm(ModelForm):
    class Meta:
        fields = ('url', 'name') # This will restrict the user to only modifying this data
        model = URLModel # Or whatever your model is called

class UpdateURLForm(ModelForm):
    class Meta:
        fields = ('name',) # Restrict user only to modifying the name
        model = URLModel

On Mon, Jul 30, 2012 at 5:00 PM, Paul <peebor@gmail.com> wrote:
That would be an option as well indeed. In fact i have 1 (base)-form for the model that i subclass for create, read and update operations. The difference is that create and update have a submit button, read doesn't, and in the read view, the fields are read-only.

The website becomes authenticated using a background process, the idea is that as soon as it becomes authenticated the url cannot be changed any more.

I have tested with readonly=True which works correctly apart from the fact that i don't think it's safe to only make the field readonly, i want to add some logic in the post-logic as well (so for example using custom validation).

A simpler alternative is to remove the 'update' button altogether, but also in this case the view should also throw a 404 or 500 just in case someone manually modifies the url.... (which is by the way very easy to do so).

Paul



Op maandag 30 juli 2012 00:00:48 UTC+2 schreef Kurtis het volgende:
Just to get some more information about the problem; Do you allow your users to initially insert the Name+URL? When does this become "authenticated"?

Maybe you could have two forms. One that allows users to add new Name+URL Objects (not sure what your object/Model is called) and another to allow them to edit (Using Django's 'fields' meta attribute to limit them to only modify the "Name" of the object)

On Sun, Jul 29, 2012 at 5:47 PM, Paul wrote:
I have a model for Websites that has 3 fields: name, url and authenticated. With a form both the name and url can be changed, but when the website is authenticated i don't want to allow that the url changes.

I'm thinking about making the url (form) field readonly but in html the field becomes still an input field (just with readonly="True"), so i have doubts whether hackers will be able to post a changed value anyhow (i'll need to test this).

Another approach is to add some custom form validation against the (current) model, but i have doubts whether validation is the solution for this?

Thanks for any directions
Paul

--
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/-/urE06kkuNBIJ.
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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/xn9xV2ukteUJ.

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: Error in Brand New Django 1.4.1 released Yesterday

On Tue, 31 Jul 2012 00:50:57 -0700 (PDT), JJ Zolper
<codingatmt@gmail.com> declaimed the following in
gmane.comp.python.django.user:

> Okay I'm sure it's fine but I was able to get a hold of 1.4 from python.org
> and I used that when installing Django

"1.4 from python.org"... Reading that bluntly sounds like you dug up
a 10-15 year old version of PYTHON. As I recall, Django wants/needs a
mid-2.x Python (not sure if Python 2.4 is supported any more, I think
Python 2.5 is okay)
--
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 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 with a Custom, Dynamic Form (using BaseForm)

Hi,

Have hit a huge roadblock trying to implement a custom, dynamic form into my django project. Although I am more familiar with using ModelForms, I need to use BaseForm to work with the structure I already have in place.

I have a dictionary of objects inside of my Model 'Photographer' that I am trying to pass into my form. The objects from 'Photographer' will be a drop down option for the user to select from, then will become part of an instance of another model 'A' after the user submits the form. I cannot figure out how to include the objects from 'Photographer' into my form, given the following form structure:

    class AForm(BaseForm):
        def __init__(self, data=None, files=None, instance=None, auto_id='id_%s',
                     prefix=None, initial=None, error_class=ErrorList,
                     label_suffix=':', empty_permitted=False):

            if not instance:
                raise NotImplementedError("Instance must be provided")

            self.instance = instance
            object_data = self.instance.fields_dict()
            self.declared_fields = SortedDict()
            self.base_fields = fields_for_a(self.instance)

            # if initial was provided, it should override the values from instance
            if initial is not None:
                object_data.update(initial)

            BaseForm.__init__(self, data, files, auto_id, prefix, object_data,
                              error_class, label_suffix, empty_permitted)

            cleaned_data = self.cleaned_data

            # save fieldvalues for self.instance
            fields = field_list(self.instance)

            for field in fields:
                if field.enable_wysiwyg:
                    value = unicode(strip(cleaned_data[field.name]))
                else:
                    value = unicode(cleaned_data[field.name])

            return self.instance

For a more full representation of the problem in general, including all of the models and a lot of the view code, please see my stack overflow question: http://stackoverflow.com/questions/11548992/adding-values-to-complex-django-view. 

I cannot thank you enough for any advice given. I have been struggling with this issue for over a month, sadly. I appreciate any commentary.


Thank you!

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

Catch or raise exception designissue

[sorry for the late response; this got lost in drafts, but it's enough of a sore point for me to want to post it]

On Sun, Jul 15, 2012 at 12:30 PM, Jani Tiainen <redetin@gmail.com> wrote:
I think "letting to explode" is all about coloring the bike shed. It all depends on a API contract - if parameter is required (thus meaning missing it is a critical error) it should explode. 

In case of incorrect request I prefer to raise 400 (Bad Request) with some explanation what went wrong. Since 500 is usually meant for "catch all" unexpected errors that happened in web server and server can't be more precise what happened. I've done that according to RFC 2616 (HTTP 1.1 Specification) where is said that 4xx codes are meant for "client side error" (Section 10.4), and 5xx which means "server error" (Section 10.5)

But I think all of that is matter of taste...


I wouldn't call it a matter of taste; this is the spec for communicating over HTTP.

Certainly, if you have full and complete control over the server, and over every client, then by all means use 500 errors to mean whatever you want. You could also signal an error with a 200 OK message, or just make up your own status codes.

Status codes have meaning though, which is important as soon as you want to open up your interface to any other clients. A 400-series code means that the client request had a problem, and the specific code tells the client whether there is anything that can be done about it.

A 500 error, on the other hand, means that there is an error (read: bug) in the web server code. Something happened (almost certainly in response to a client request) that the server was not properly coded to handle, and the result was an unexpected exception.

The distinction is important: it communicates who has the responsibility (or at least the capability) to fix the error.

As developers, we should be reporting 400-series errors every time we can detect an issue with a request, as a courtesy to clients. We should never deliberately be creating 500 errors. The only responsible thing to do when a 500 is seen in the logs is to track down the source of it and fix the bug.

--
Regards,
Ian Clelland
<clelland@gmail.com>


--
Regards,
Ian Clelland
<clelland@gmail.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.

Re: presenting a manytomany relationship in a tabular way

On 31-7-2012 11:33, goabbear wrote:

> There's 3 tables, user(name, mail), mailinglist(name) and an intermediate
> table subscription where are stored all the users joining some
> mailinglists.
> How can I present the "subscription" table to the admins like a
> spreadsheet, where the first column represents the users emails and one
> other column is a mailinglist name. On each row, the admin can activate the
> subscription for each user by checking a checkbox?

You need a combination of list_display and modeladmin actions:
<https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display>
<https://docs.djangoproject.com/en/1.4/ref/contrib/admin/actions/>

Alternatively, you can use list_editable:
<https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable>

--
Melvyn Sopacua

--
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: Exlude xampp-htdocs-projects from beeing treated as Django projects?

On 31-7-2012 11:33, AnotherGuyver wrote:

> The Django installation seems to work allright. However,
> when I switch to my other projects, which don't use Django, e.g.
> loclhost/project1, they're still treated as Django Projects or at least the
> Django welcome page is beeing displayed instead of the index.html of the
> current project. Even 'localhost/project1/index.html' still brings me back
> to the Django page. Do I have to exclude my other Projects somehow? Or am I
> doing something wrong alltogether?

What you're doing wrong is following a tutorial that doesn't cover your
situation (and you don't seem to be familiar with the underlying
mod_wsgi technology).
Your error is caused by the fact that you refer all locations to django
in your webserver and the solution is to study mod_wsgi documentation on
how to route a location to a specific WSGI application.
To mod_wsgi, django is a WSGI application and so are your other projects
(if they previously worked as wsgi applications) or they are implemented
differently.
You should either route everything by default to django and override
your project locations or only route locations specific to django to the
django wsgi application and let everything else be handled by the webserver.
What is best for your situation only you can decide.
--
Melvyn Sopacua

--
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: merge data from multiple models

On 31-7-2012 14:36, Joris wrote:

> class SlowModel(models.Model):
> rid_fastmodel = models.IntegerField(primary_key=True)
> calcfield1 = models.TextField(blank=True)
> calcfield2= models.TextField(blank=True)
>
> SQLstatement = "SELECT rid_fastmodel, calcfield1, calcfield2 from (SELECT
> ....) JOIN (...) JOIN (...) WHERE some_condition = %s"
>
> Is this better?

Yep, dive into PostgreSQL views [1]. It should be possible to create a
view that yields the same fields as your SlowModel class and you can use
a OneToOneField in the SlowModel corresponding the view's rid_fastmodel.
syncdb becomes your enemy, but it is the cleanest solution.

[1] http://www.postgresql.org/docs/9.1/static/sql-createview.html,
http://www.postgresql.org/docs/9.1/static/tutorial-views.html
--
Melvyn Sopacua

--
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 more data to Generic Views

On 31-7-2012 6:17, Lachlan Musicman wrote:

> I have Person, Certificate, Job and Compensation objects. The last three
> all
> have an FK (or M2M) back to a (or some) Person(s).
>

So reverse relations.

> def get_context_data(self,**kwargs):
> #Call the base implementation first to get a context
> context = super(PersonDetailView, self).get_context_data(**kwargs)
> #Add in a querysets
> context['job_list'] = Vacancy.complete.all()
> context['certificate_list'] = Certificate.objects.all()
> context['claim_list'] = Compensation.objects.all()

You don't need any of these. In your template, simply call:
{{ person.certificate_set.fieldname }}

If you insist on having them available as you do above, they should be:
context['job_list'] = self.get_object().vacancy_set.all()
context['certificate_list'] = self.get_object().certificate_set.all()
context['claim_list'] = self.get_object().compensation_set.all()

Required reading:
https://docs.djangoproject.com/en/1.4/ref/models/relations/

Also, skipping the tutorial is not recommended:
<https://docs.djangoproject.com/en/1.4/intro/tutorial03/#use-the-template-system>

> Of course, the other thing that I can't help but thinking is that at this
> point, the non-generic-view method of urls/views might be a simpler way to
> go. While Generic Views are quite versatile, is there a point at which
> they are considered to restricting?

Not really. The only thing that bugs me about them is that adding extra
context requires sub-classing so you end up with a views.py that solely
consists of sub-classed generic views with 3 lines of get_context_data().
--
Melvyn Sopacua

--
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: access the state of a Model object prior to it's modification ?



On Mon, Jul 30, 2012 at 6:22 PM, Tomas Neme <lacrymology@gmail.com> wrote:

uhm, if you register a listener to the pre_save signal, then you can do this:


if instance.published:
  # the instance about to be saved has the published flag on
  dbojb = MyModel.objects.get(id=instance.id)


  # did it have it on the database?
  if not dbobj.published:
    do_stuff()

you probably need to check the "created" argument on the listener that tells you if the object is a new one, or a modification


Great! ... this is what I was looking for. Signals is what I meant by 
"the django way of .."

Thanks all!

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



--
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

--
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: merge data from multiple models


> Hmm, I guess I'm missing the "real world use case" for this. Most 
> importantly, I'm missing how this slow model relates to the fast model 
> and what kind of query it is executing. I'm especially curious about the 
> "as this statement is executed as an instance of the model" bit. 

Ok, I'll try to explain this better. The fast model is coupled directly to a table. The Slow model is not, it is activated by a specific sql query that depends on a specific condition.
AFAIK to get data from the slow model, I do:
SLOMO = SlowModel.objects.raw( SQLstatement ,[CONDITION]) 

However, if I set the primary_key of SlowModel to OneToOne (pointing to FastModel), as suggested above, and try to retreive SlowModel data from FastModel  (FastModelInstance.slow) I get an error that data is missing. My guess was that this was because I did not manage to tell the instance of Fastmodel that it first needs to pass the SQL to its SlowModel connection before I can ask it questions.

#-------------------------------
class FastModel(models.Model):
    idgroup = models.IntegerField(primary_key=True)
    field1 = models.IntegerField()
    field2 = models.CharField(max_length=250, blank=True)
    field3 = models.CharField(max_length=250, blank=True)
    class Meta:
        db_table = u'my_db_table'
   
class SlowModel(models.Model): 
    rid_fastmodel = models.IntegerField(primary_key=True)
    calcfield1 = models.TextField(blank=True)
    calcfield2= models.TextField(blank=True)

SQLstatement = "SELECT rid_fastmodel, calcfield1, calcfield2 from (SELECT ....) JOIN (...) JOIN (...) WHERE some_condition = %s"

Is this better?

thanks
joris

 

--
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/-/TPkzlZJ7NfkJ.
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: merge data from multiple models

On 30-7-2012 19:50, joris benschop wrote:
>
>
> Op maandag 30 juli 2012 16:06:38 UTC+2 schreef Joris het volgende:
>>
>>
>>
>> On Monday, July 30, 2012 3:52:31 PM UTC+2, Melvyn Sopacua wrote:
>>>
>>>
>>> If this is not implemented as a OneToOneField, then do so. You can then
>>> access the related object in the same way as the reverse of a ForeignKey
>>> and use related_name to make this more intuitive.
>>>
>>
>> Yes that works great. Thanks!!
>>
>>
>>
> I'm sorry I spoke too soon. This does not work if the slow model is based
> on a raw SQL statement, as this statement is performed on an instance of
> the model. Referring to fastmodel.slow creates a new (unititialized)
> instance with no SQL backend and this crashes (relation does not exist).

Hmm, I guess I'm missing the "real world use case" for this. Most
importantly, I'm missing how this slow model relates to the fast model
and what kind of query it is executing. I'm especially curious about the
"as this statement is executed as an instance of the model" bit.

Using a view in PostgreSQL for that SQL statement and tying that to a
model seems like the obvious solution, but care should be taken with the
syncdb command (as in, the model tied to the view should not be 'synced').

--
Melvyn Sopacua

--
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 more data to Generic Views

So, in conclusion, Lachlan, you would want to do something like:

 def get_context_data(self,**kwargs):
        #Call the base implementation first to get a context
        context = super(PersonDetailView, self).get_context_data(**kwargs)
        #Add in a querysets
        context['job_list'] = Vacancy.complete.filter(person_id=self.kwargs[self.pk_url_kwarg])
        context['certificate_list'] = Certificate.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
        context['claim_list'] = Compensation.objects.filter(person_id=self.kwargs[self.pk_url_kwarg])
        return context

I have not tested this, but it gives you the idea. You'll want to filter the Vacancy, Certificate and Compensation objects by the person's ID. 

Good luck

Tervitades/Regards
Karl Sutt


On Tue, Jul 31, 2012 at 12:07 PM, Per-Olof Åstrand <p.o.aastrand@gmail.com> wrote:
Hi,

I just started to convert my small hobby-project into class-based views and struggled with similar things (but with a ListView instead).

The person object is in the context dictionary, so you need to refer to it by context['person'].

More generally, it is instructive to print context, kwargs and self.kwargs inside the get_context_data method. That would give you the information you need. It took me some time to realize that url-captured parameters are available in self.kwargs.

Per-Olof


On Tuesday, July 31, 2012 6:17:26 AM UTC+2, Lachlan Musicman wrote:
Hola,

I'm confused about adding extra content to a class based Generic View. I've read
the docs at file:///home/datakid/src/django-docs/topics/class-based-views.html 
and have written the code accordingly. 

I have Person, Certificate, Job and Compensation objects. The last three all 
have an FK (or M2M) back to a (or some) Person(s).

My DetailView subclass (which I've put in views.py - is there a better or more
correct place for it?)

class PersonDetailView(DetailView):
    context_object_name = "person"
    model = Person

    def get_context_data(self,**kwargs):
        #Call the base implementation first to get a context
        context = super(PersonDetailView, self).get_context_data(**kwargs)
        #Add in a querysets
        context['job_list'] = Vacancy.complete.all()
        context['certificate_list'] = Certificate.objects.all()
        context['claim_list'] = Compensation.objects.all()
        return context

But I don't want the full list of Vacancies, Certificates or Claims - I just 
want those that are linked to the person - how can I filter by these? I've tried
.filter(self.get_id)
.filter(self.request.get_id)
.filter(self.person.get_id)
.filter(self.request.person.get_id)
.filter(applicants__get_id__exact=self.get_id) (in the case of Vacancy) etc

How do I filter by the person object that is already in the context?
I know the answer is simple - I should wait until tomorrow when my brain is 
fresher, but I want to finish this off tonight if possible.

Of course, the other thing that I can't help but thinking is that at this point, the non-generic-view method of urls/views might be a simpler way to go. While Generic Views are quite versatile,  is there a point at which they are considered to restricting? 

L.

--
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/-/6O_nqDwvAAEJ.

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: merge data from multiple models

Hi there,

> As templates cannot do lookups into a dictionary....

Templates can do lookups into a dictionary, see
https://docs.djangoproject.com/en/1.4/topics/templates/#variables
(check the "Behind the scenes" section).

From what you've described, I'd try to prepare the necessary data in
a view (using caching, if possible at all), build the appropriate data
structure to be displayed and then use the template layer to do a
"dummy" display. Then you'd have the full power of Python at your
disposal to perform the best access to your data and combining the
models together into and array of items or a dictionary, depending on
your need.

HTH

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

Exlude xampp-htdocs-projects from beeing treated as Django projects?

Hey guys,

I'm using XAMPP and I'm pretty new to Django, so I followed this tutorial to get me started. The Django installation seems to work allright. However, when I switch to my other projects, which don't use Django, e.g. loclhost/project1, they're still treated as Django Projects or at least the Django welcome page is beeing displayed instead of the index.html of the current project. Even 'localhost/project1/index.html' still brings me back to the Django page. Do I have to exclude my other Projects somehow? Or am I doing something wrong alltogether?

Regards,
AnotherGuyver

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

presenting a manytomany relationship in a tabular way

Hi all,
I start with django but after some searches I can't do what I want in the admin section of my app.
There's 3 tables, user(name, mail), mailinglist(name) and an intermediate table subscription where are stored all the users joining some mailinglists. 
How can I present the "subscription" table to the admins like a spreadsheet, where the first column represents the users emails and one other column is a mailinglist name. On each row, the admin can activate the subscription for each user by checking a checkbox?
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/-/OJSABe8rdWUJ.
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 more data to Generic Views

Hi,

I just started to convert my small hobby-project into class-based views and struggled with similar things (but with a ListView instead).

The person object is in the context dictionary, so you need to refer to it by context['person'].

More generally, it is instructive to print context, kwargs and self.kwargs inside the get_context_data method. That would give you the information you need. It took me some time to realize that url-captured parameters are available in self.kwargs.

Per-Olof

On Tuesday, July 31, 2012 6:17:26 AM UTC+2, Lachlan Musicman wrote:
Hola,

I'm confused about adding extra content to a class based Generic View. I've read
the docs at file:///home/datakid/src/django-docs/topics/class-based-views.html 
and have written the code accordingly. 

I have Person, Certificate, Job and Compensation objects. The last three all 
have an FK (or M2M) back to a (or some) Person(s).

My DetailView subclass (which I've put in views.py - is there a better or more
correct place for it?)

class PersonDetailView(DetailView):
    context_object_name = "person"
    model = Person

    def get_context_data(self,**kwargs):
        #Call the base implementation first to get a context
        context = super(PersonDetailView, self).get_context_data(**kwargs)
        #Add in a querysets
        context['job_list'] = Vacancy.complete.all()
        context['certificate_list'] = Certificate.objects.all()
        context['claim_list'] = Compensation.objects.all()
        return context

But I don't want the full list of Vacancies, Certificates or Claims - I just 
want those that are linked to the person - how can I filter by these? I've tried
.filter(self.get_id)
.filter(self.request.get_id)
.filter(self.person.get_id)
.filter(self.request.person.get_id)
.filter(applicants__get_id__exact=self.get_id) (in the case of Vacancy) etc

How do I filter by the person object that is already in the context?
I know the answer is simple - I should wait until tomorrow when my brain is 
fresher, but I want to finish this off tonight if possible.

Of course, the other thing that I can't help but thinking is that at this point, the non-generic-view method of urls/views might be a simpler way to go. While Generic Views are quite versatile,  is there a point at which they are considered to restricting? 

L.

--
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/-/6O_nqDwvAAEJ.
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.