Re: Making a rather small web app, is Django right for it?
It's more of a nice-to-have for work. But yeah, it'll not be a very large project. Devin Prater Technical Assistant 256 761-3423 [image: Alabama Institute for Deaf and Blind] P.O. Box 698 | 1105 Fort Lashley Ave. Talladega, AL 35161 www.aidb.org [image: Facebook] Discover how we’re limitless. <https://www.facebook.com/AlabamaInstituteforDeafandBlind?ref=notif_t=fbpage_fan_invite> On Tue, May 25, 2021 at 12:54 AM Antonis Christofides < anto...@antonischristofides.com> wrote: > It's hard to say. While Django *is* suitable, it's also large. If you > don't know it already, you might not want to learn it just for this. It's > possible Flask would be a better choice, since it's smaller and (I think) > easier. (Note: I'm a Django developer, and I'm not a Flask developer.) > > So I think it's mostly a question of what you want: Why do you want to do > this project? Is it commercial? Is it a hobby? Is it something you do > because you find it appealing? If it's something like a hobby, pick up > whatever seems more fun to you. > > Regards, > > Antonis > > Antonis Christofides > +30-6979924665 (mobile) > > > > On 24/05/2021 17.37, Devin Prater wrote: > > Hi all. I am a rather new Python learner, although I've made the following > script: > > https://github.com/prater-devin/src/blob/main/lunch/lunch.py > > I want to turn this into a central place where students can get not just > the lunch menu, but also other menus, upcoming events, things like that, > but not much more than that. So, in order to bypass the need for submitting > to the App Store because this isn't that big of an app, I decided to go > with web development instead. Since I already know Python, enough to make > that simple program at least, I thought I'd just use Django to make this. > > Now, I've also tried using Beeware to make an actual app, and that seems > easy compared to getting started with Django, but I don't want to disregard > Django just because Beeware is easier. Plus Beeware doesn't seem to have > web app creation support yet. So, any ideas? How hard would it be to take > something like that simple code, probably for the backend more than > frontend, and enhance it, mainly adding more requests to a URL, then > getting text using BS4, then showing it on the app? I imagine tabs at the > bottom of the screen for "menus", "vending machines", and "events and > news." Stuff like that, then the main content in the middle, then buttons > at the top to change between menu sources on the menus tab and such. So, > not that much interaction I'd think. So, what do you all think? Thanks for > any help. > > Devin Prater > > Technical Assistant > > > 256 761-3423 > > [image: Alabama Institute for Deaf and Blind] > > P.O. Box 698 | 1105 Fort Lashley Ave. > > Talladega, AL 35161 > > www.aidb.org > [image: Facebook] Discover how we’re limitless. > <https://www.facebook.com/AlabamaInstituteforDeafandBlind?ref=notif_t=fbpage_fan_invite> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAKXtajAeZPSpgZg9a38YtCksi4N7VF51DJYxWAQ1K0P3V%3D-P_A%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAKXtajAeZPSpgZg9a38YtCksi4N7VF51DJYxWAQ1K0P3V%3D-P_A%40mail.gmail.com?utm_medium=email_source=footer> > . > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/90a0185c-d744-826c-c1b7-d459d23d18a3%40antonischristofides.com > <https://groups.google.com/d/msgid/django-users/90a0185c-d744-826c-c1b7-d459d23d18a3%40antonischristofides.com?utm_medium=email_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKXtajAiCKrzXgZ6Y8bZFQZggpeE_N3DaFSTwunTjY5Y%3DgqtuA%40mail.gmail.com.
Making a rather small web app, is Django right for it?
Hi all. I am a rather new Python learner, although I've made the following script: https://github.com/prater-devin/src/blob/main/lunch/lunch.py I want to turn this into a central place where students can get not just the lunch menu, but also other menus, upcoming events, things like that, but not much more than that. So, in order to bypass the need for submitting to the App Store because this isn't that big of an app, I decided to go with web development instead. Since I already know Python, enough to make that simple program at least, I thought I'd just use Django to make this. Now, I've also tried using Beeware to make an actual app, and that seems easy compared to getting started with Django, but I don't want to disregard Django just because Beeware is easier. Plus Beeware doesn't seem to have web app creation support yet. So, any ideas? How hard would it be to take something like that simple code, probably for the backend more than frontend, and enhance it, mainly adding more requests to a URL, then getting text using BS4, then showing it on the app? I imagine tabs at the bottom of the screen for "menus", "vending machines", and "events and news." Stuff like that, then the main content in the middle, then buttons at the top to change between menu sources on the menus tab and such. So, not that much interaction I'd think. So, what do you all think? Thanks for any help. Devin Prater Technical Assistant 256 761-3423 [image: Alabama Institute for Deaf and Blind] P.O. Box 698 | 1105 Fort Lashley Ave. Talladega, AL 35161 www.aidb.org [image: Facebook] Discover how we’re limitless. <https://www.facebook.com/AlabamaInstituteforDeafandBlind?ref=notif_t=fbpage_fan_invite> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKXtajAeZPSpgZg9a38YtCksi4N7VF51DJYxWAQ1K0P3V%3D-P_A%40mail.gmail.com.
Upload file IN DJANGO
please help me i want to upload a file in my django application how to save in a database(postgresql) an upload file in django ... thank for your answers . -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9d1545eb-5c94-42d3-8881-64c2c3499c8a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: display the elements from a database in a forms
2 months ago yes !! please i need your help .. it's very importante for me !!! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4e940333-c67c-46ce-a38d-e279fa4c62bf%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
display the elements from a database in a forms
hi I want to know how to display the elements from a database in a django forms ? i use postgresql . please help me -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/208b5083-39f2-4c7e-9220-830591799b0b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: simultaneously submit three forms on the same page
I tried it .. but it is only the first form ( {{ emet_form.as_p }}) that is saved.. {% csrf_token %} {{ emet_form.as_p }} {{ des_form.as_p }} {{ fich_form.as_p }} On Wednesday, July 30, 2014 9:19:11 AM UTC, Tom Evans wrote: > > On Wed, Jul 30, 2014 at 10:04 AM, Devin Cky <vin1...@gmail.com > > wrote: > > > > > > > > > > thank you very much .. how is the template for such a view ... I've put > each form in a form tag like that > > Only one can be submitted at a time, so if you want all three > Forms to be submitted at the same time, they must all be inside one > . > > Cheers > > Tom > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ec7666ef-5476-4a86-ba5d-b87199a5ee45%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: simultaneously submit three forms on the same page
thank you very much .. how is the template for such a view ... I've put each form in a form tag like that EMETTEUR {% csrf_token %} {{ emet_form.as_p }} DESTINATAIRE {% csrf_token %} {{ des_form.as_p }} FICHIER {% csrf_token %} {{ fich_form.as_p }} {% csrf_token %} On Tuesday, July 29, 2014 7:34:16 PM UTC, C. Kirby wrote: > > > > They are not getting validated, or validation is failing? > Also, it looks like you are using model forms. You can get rid of all the > for,.cleaned_data.get lines and just use: > > if emet_form.is_valid() and des_form.is_valid() and fich_form.is_valid(): > emet = emet_form.save() > des = des_form.save() > fich = fich_form.save() > > > On Tuesday, July 29, 2014 10:53:59 AM UTC-5, Devin Cky wrote: >> >> >> >> On Tuesday, July 29, 2014 1:48:00 PM UTC, Tom Evans wrote: >>> >>> On Tue, Jul 29, 2014 at 12:31 PM, Devin Cky <vin1...@gmail.com> wrote: >>> > hi i am a beginner in django and I have a problem .. how can I >>> validate 3 >>> > forms on the same page simultaneously ..please help me >>> > >>> >>> If they are different types of forms, you cannot use a formset. >>> >>> In that case, just test whether all forms are valid. If they are all >>> valid, save/process the forms. If not, re-render the page with the >>> bound forms and display the errors. >>> >>> Eg >>> >>> def myview(request): >>> if request.method == 'POST': >>> form_a = FormA(request.POST) >>> form_b = FormB(request.POST) >>> form_c = FormC(request.POST) >>> if form_a.is_valid() and form_b.is_valid() and form_c.is_valid(): >>> form_a.save() >>> >>> return HttpResponseRedirect(...) >>> else: >>> form_a = FormA() >>> form_b = FormB() >>> form_c = FormC() >>> return render(...) >>> >>> Cheers >>> >>> Tom >>> >> >> >> >> >> >> ---thank you TOM--- >> when I submit my forms .. no field is validated >> >> >> ...view. >> >> >> >> def enregistrer(request): >> if request.method == 'POST': >> emet_form = EmetteurForm(request.POST, prefix = "emet") >> des_form = DestinataireForm(request.POST, prefix = "des") >> fich_form = FichierForm(request.POST, prefix = "fich") >> if emet_form.is_valid() and des_form.is_valid() and >> fich_form.is_valid(): >> civilite = emet_form.cleaned_data.get('civilite') >> nom = emet_form.cleaned_data.get('nom') >> prenom = emet_form.cleaned_data.get('prenom') >> >> cni = emet_form.cleaned_data.get('cni') >> mail = emet_form.cleaned_data.get('mail') >> telephone = >> emet_form.cleaned_data.get('telephone') >> pays = emet_form.cleaned_data.get('pays') >> ville = emet_form.cleaned_data.get('ville') >> quartier = emet_form.cleaned_data.get('quartier') >> emet = emet_form.save() >> nom = des_form.cleaned_data.get('nom') >> prenom = des_form.cleaned_data.get('prenom') >> mail = des_form.cleaned_data.get('mail') >> telephone = des_form.cleaned_data.get('telephone') >> des = des_form.save() >> description_fichier = >> fich_form.cleaned_data.get('description_fichier') >> date_enregistrement = >> fich_form.cleaned_data.get('date_enregistrement') >> observation = >> fich_form.cleaned_data.get('observation') >> montant_prestation = >> fich_form.cleaned_data.get('montant_pres
Re: simultaneously submit three forms on the same page
On Tuesday, July 29, 2014 1:48:00 PM UTC, Tom Evans wrote: > > On Tue, Jul 29, 2014 at 12:31 PM, Devin Cky <vin1...@gmail.com > > wrote: > > hi i am a beginner in django and I have a problem .. how can I validate > 3 > > forms on the same page simultaneously ..please help me > > > > If they are different types of forms, you cannot use a formset. > > In that case, just test whether all forms are valid. If they are all > valid, save/process the forms. If not, re-render the page with the > bound forms and display the errors. > > Eg > > def myview(request): > if request.method == 'POST': > form_a = FormA(request.POST) > form_b = FormB(request.POST) > form_c = FormC(request.POST) > if form_a.is_valid() and form_b.is_valid() and form_c.is_valid(): > form_a.save() > > return HttpResponseRedirect(...) > else: > form_a = FormA() > form_b = FormB() > form_c = FormC() > return render(...) > > Cheers > > Tom > ---thank you TOM--- when I submit my forms .. no field is validated ...view. def enregistrer(request): if request.method == 'POST': emet_form = EmetteurForm(request.POST, prefix = "emet") des_form = DestinataireForm(request.POST, prefix = "des") fich_form = FichierForm(request.POST, prefix = "fich") if emet_form.is_valid() and des_form.is_valid() and fich_form.is_valid(): civilite = emet_form.cleaned_data.get('civilite') nom = emet_form.cleaned_data.get('nom') prenom = emet_form.cleaned_data.get('prenom') cni = emet_form.cleaned_data.get('cni') mail = emet_form.cleaned_data.get('mail') telephone = emet_form.cleaned_data.get('telephone') pays = emet_form.cleaned_data.get('pays') ville = emet_form.cleaned_data.get('ville') quartier = emet_form.cleaned_data.get('quartier') emet = emet_form.save() nom = des_form.cleaned_data.get('nom') prenom = des_form.cleaned_data.get('prenom') mail = des_form.cleaned_data.get('mail') telephone = des_form.cleaned_data.get('telephone') des = des_form.save() description_fichier = fich_form.cleaned_data.get('description_fichier') date_enregistrement = fich_form.cleaned_data.get('date_enregistrement') observation = fich_form.cleaned_data.get('observation') montant_prestation = fich_form.cleaned_data.get('montant_prestation') fich = fich_form.save() else: emet_form = EmetteurForm() des_form = DestinataireForm() fich_form = FichierForm() return render(request,'formulaire/information.html',locals()) //***please look ..if my view is good***// -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3948ad1e-acbc-4185-a02d-ea5ed76717d5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
simultaneously submit three forms on the same page
*hi i am a beginner in django and I have a problem .. how can I validate 3 forms on the same page **simultaneously ..please help me* -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/146660c0-083a-452b-b519-206c8bb2a1c2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How do I construct a queryset for this complex query?
I've got a complex query that uses a combination of Q objects and qargs to produce the following query: Note the T4 alias...this is central to the question. SELECT `t_answer`.`id`, `t_answer`.`question_id`, `t_answer`.`survey_id`, `t_answer`.`content_type_id`, `t_intanswer`.`answer_ptr_id`, `t_intanswer`.`value` FROM `t_intanswer` INNER JOIN `t_answer` ON (`t_intanswer`.`answer_ptr_id` = `t_answer`.`id`) INNER JOIN `t_survey` ON (`t_answer`.`survey_id` = `t_survey`.`id`) INNER JOIN `t_answer` T4 ON (`t_survey`.`id` = T4.`survey_id`) INNER JOIN `t_booleananswer` ON (T4.`id` = `t_booleananswer`.`answer_ptr_id`) INNER JOIN `t_choiceanswer` ON (T4.`id` = `t_choiceanswer`.`answer_ptr_id`) INNER JOIN `t_facility` ON (`t_survey`.`facility_id` = `t_facility`.`id`) WHERE ( ( (`t_booleananswer`.`value` = True AND T4.`question_id` = 1742) AND (`t_choiceanswer`.`choice_id` = 1947 AND T4.`question_id` = 1743 ) ) AND `t_survey`.`public` = False AND `t_survey`.`facility_id` = 82 AND `t_survey`.`doctor_id` = 124 AND `t_answer`.`question_id` = 1753 AND `t_facility`.`program_id` = 71 AND `t_survey`.`completed` IS NOT NULL AND `t_survey`.`flagged` = False AND `t_survey`.`completed` < '2012-05-20 00:00:00' AND `t_survey`.`completed` > '2012-05-18 00:00:00' ) I'm looking for a result that contains either a boolean or choice answer, but I've used Django's model inheritance, and both tables are trying to join through t_answer. Only one t_answer row can be returned for this query, so I get back zero results. But I need one result. Here is the modified query in raw SQL that solves my problem. I create a second FROM clause using the alias T5, then I join choice on that. Works great. SELECT `t_answer`.`id`, `t_answer`.`question_id`, `t_answer`.`survey_id`, `t_answer`.`content_type_id`, `t_intanswer`.`answer_ptr_id`, `t_intanswer`.`value` FROM `t_intanswer` INNER JOIN `t_answer` ON (`t_intanswer`.`answer_ptr_id` = `t_answer`.`id`) INNER JOIN `t_survey` ON (`t_answer`.`survey_id` = `t_survey`.`id`) INNER JOIN `t_answer` T4 ON (`t_survey`.`id` = T4.`survey_id`) INNER JOIN `t_answer` T5 ON (`t_survey`.`id` = T5.`survey_id`) INNER JOIN `t_booleananswer` ON (T4.`id` = `t_booleananswer`.`answer_ptr_id`) INNER JOIN `t_choiceanswer` ON (T5.`id` = `t_choiceanswer`.`answer_ptr_id`) INNER JOIN `t_facility` ON (`t_survey`.`facility_id` = `t_facility`.`id`) WHERE ( ( (`t_booleananswer`.`value` = True AND T4.`question_id` = 1742) AND (`t_choiceanswer`.`choice_id` = 1947 AND T5.`question_id` = 1743 ) ) AND `t_survey`.`public` = False AND `t_survey`.`facility_id` = 82 AND Cool...so I have my solution---except that I don't know how to construct it using the Django queryset. I looked at "extra" (https:// docs.djangoproject.com/en/1.3/ref/models/querysets/#extra) but I'm not clear on how to use it accomplish my second INNER JOIN T5. Any thoughts experts? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Save Handlers and a newbie to Django
Thanks everyone, I tried using some signal handlers but it wasn't happening so I reverted to the override of the save method and now I have it working. Regards, Devin Morin On Oct 15, 8:56 am, Blue Cuenca <azue...@gmail.com> wrote: > On 10/15/2010 9:01 PM, Devin M wrote:> Hello everyone, > > I am writing a save handler in my models.py file to run a few > > actions after a save. to do this I have a function called make_photos > > and a connection to the post_save signal. > > Here is my code: > > > > > The only problem i have with this code is that it runs every save. So > > it creates a infinite loop of sorts and I dont know how to make it > > perform this action once. Is there another signal I should use? Any > > ideas? > > > Regards, > > Devin M > > You may want to look at > this:http://snipt.net/danfreak/generate-thumbnails-in-django-with-pil/ > > The snippet above overrides the save method. Before calling the actual > save (super), the thumbnail fields is dynamically created (using PIL). > I am sure you can add code that will do the same thing for your "large" > photo field. > > regards, > Blue C -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using a non-DB backend
For more than one database it seems that you are able to do it http://docs.djangoproject.com/en/dev/topics/db/multi-db/. You could implement your device functions inside something like myproject.device.functions if your not working with alot of data. Or you can implement that in the database handler. Regards, Devin M On Oct 15, 12:25 pm, Damir Dezeljin <damir.dezel...@gmail.com> wrote: > Thanks. > > I read the docs you pointed med to and now I have few more questions: > 1. Is it possible to use two or more different back-ends with a single > Django project? For me it seems not. > > 2. After rethinking my needs I realized I need simple functions as e.g. > FlushDevice(), GetServerUptime(), AssignUserToDevice(), etc. This doesn't > really seem to be a lot of data so I'm wondering what do you suggest on how > or where to implement the required interfaces? > > Sincerely, > Damir > > On Fri, Oct 15, 2010 at 15:35, Devin M <devin...@gmail.com> wrote: > > Hello, > > It looks like you want a custom database backend. On > >http://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#engine > > they say > > "You can use a database backend that doesn't ship with Django by > > setting ENGINE to a fully-qualified path (i.e. > > mypackage.backends.whatever). Writing a whole new database backend > > from scratch is left as an exercise to the reader; see the other > > backends for examples." > > So i suppose you can look to the other backends for examples. > > > Regards, > > Devin Morin > > > On Oct 15, 6:21 am, Damir Dezeljin <damir.dezel...@dezo.org> wrote: > > > Hi. > > > > I'm working on an application tat communicates with embedded devices > > > connected to the LAN. The devices are controlled by a central server > > written > > > in C++. Django is used for the front-end or better to say the GUI for the > > > server. > > > > Part of the data the user needs access too are stored in the database, > > hence > > > the Django DB API to access this data; however, there are certain data > > and > > > actions that requires direct communication with the C++ server. The > > > communication is implemented using CORBA (OmniORBpy). E.g. of a situation > > > where the CORBA interface between the GUI and the server is needed is the > > > flush of devices configuration or update of the following and this should > > be > > > real time and not implemented polling the DB. > > > > Currenly I'm instantiating the CORBA interface to my server in the > > views.py. > > > I'm wondering if there is a better way to do it as I just don't see how > > > could I put the CORBA interface in the Model part of the GUI? << I'm > > still > > > confused by MVC approaches certain frameworks like CakePHP use. I think > > > Django is not such a framework; however, I still think I should somehow > > > separate the data layer from the business logic (bottomline: Django is > > still > > > kind of a MVC framework). How can I do this? > > > > Of course I would also like to solve the problem I'm currently facing: > > > Let's suppose both the C++ server and Django web site are up and running. > > If > > > the C++ server is restarted the web page doesn't work any more until when > > I > > > restart the web server too. I instantiate the CORBA object in a global > > > scope; however, I thought there is no persistence for the Django code > > > between the web browser calls. Am I right? Why the connection to CORBA > > > ceases working in such a case? << with e.g. C++ or Python stand-alone > > > clients the connection is reestablished each time the script / program / > > ... > > > is executed. > > > > Thanks for any hint you may have, > > > Damir > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Save Handlers and a newbie to Django
Im just storing these files in standard ImageFields does the field take care of that automagically? And whats the best way to delete the files saved to tmp? should i do a system call for rm? On Oct 15, 7:41?am, Jonathan Barratt <jonathan.barr...@knifeict.com> wrote: > On 15 ?.?. 2010, at 21:35, Devin M wrote: > > > Ok its running in a infinite loop because im calling > > self.*photo.save() and that starts this loop all over again. Maybe I > > can add a field to the model like booleen resized and if its true dont > > do any resizing but if its false then perform some resizing(aka run > > the function)? also im going to have to delete these files when the > > object is deleted too. > > You can also override the delete function to take care of deleting the files > when you're getting rid of the object... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Save Handlers and a newbie to Django
Ok its running in a infinite loop because im calling self.*photo.save() and that starts this loop all over again. Maybe I can add a field to the model like booleen resized and if its true dont do any resizing but if its false then perform some resizing(aka run the function)? also im going to have to delete these files when the object is deleted too. On Oct 15, 6:01 am, Devin M <devin...@gmail.com> wrote: > Hello everyone, > I am writing a save handler in my models.py file to run a few > actions after a save. to do this I have a function called make_photos > and a connection to the post_save signal. > Here is my code: > class Album(models.Model): > title = models.CharField(max_length=200) > date = models.DateField(blank=True, null=True) > desc = models.TextField(blank=True, null=True) > comments = models.BooleanField() > published = models.BooleanField(default=True) > tags = models.CharField(max_length=200, blank=True, null=True) > def __unicode__(self): > return u'%s' % (self.title) > > class Photo(models.Model): > title = models.CharField(max_length=200, default='Untitled Photo') > album = models.ForeignKey(Album, blank=True, null=True) > desc = models.TextField(blank=True, null=True) > date = models.DateField(blank=True, null=True) > comments = models.BooleanField() > published = models.BooleanField(default=True) > tags = models.CharField(max_length=200, blank=True, null=True) > thumb_photo = models.ImageField(upload_to='thumb_images', > blank=True, null=True) > large_photo = models.ImageField(upload_to='large_images', > blank=True, null=True) > original_photo = models.ImageField(upload_to='original_images', > blank=True, null=True) > def makeimages(self): > (dirName, fileName) = os.path.split(self.original_photo.path) > (fileBaseName, fileExtension)=os.path.splitext(fileName) > > #Save the thumbnail > thumb_width = 300 > thumb_height = 300 > thumb = Image.open(self.original_photo.path) > thumb.resize((thumb_width,thumb_height), Image.ANTIALIAS) > thumb_path = "/tmp/" + str(fileBaseName) + "_thumb.jpg" > thumb.save(thumb_path, "JPEG") > thumb_img_file = open(thumb_path, 'r') > thumb_file = File(thumb_img_file) > self.thumb_photo.save(str(fileBaseName) + '_thumb.jpg', > thumb_file, save=True) > thumb_img_file.close() > > #Save the large > large_width = 1024 > large_height = 768 > large = Image.open(self.original_photo.path) > large.resize((large_width,large_height), Image.ANTIALIAS) > large_path = "/tmp/" + str(fileBaseName) + "_large.jpg" > large.save(thumb_path, "JPEG") > large_img_file = open(thumb_path, 'r') > large_file = File(thumb_img_file) > self.thumb_photo.save(str(fileBaseName) + '_large.jpg', > large_file, save=True) > large_img_file.close() > > post_save.connect(makeimages) > > The only problem i have with this code is that it runs every save. So > it creates a infinite loop of sorts and I dont know how to make it > perform this action once. Is there another signal I should use? Any > ideas? > > Regards, > Devin M -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Pagination with bound form
Wait looks like i made an error. http://testsite.com/page/{%pk - 1%}>Previous Page and you might not be able to use pk so see if you can use data.pk let me know if it works. Regards, Devin M On Oct 15, 6:56 am, Devin M <devin...@gmail.com> wrote: > Oh you want just one record per page? Thats easy. > urls.py > (r'^page/(?P\d+)/$', 'data.views.pagelisting'), > > views.py > def pagelisting(request, page_number): > data_list = Data.objects.filter(pk=page_number) > return render_to_response('list.html', {"data_list": data_list}) > > template list.html > {% if datalist %} > > {% for data in datalist %} > {{ data.text }} > {% endfor %} > > http://testsite.com/page/{%pk - 1%}>Next Page > {% else %} > No data is available. > {% endif %} > > On Oct 15, 6:43 am, David <cthl...@gmail.com> wrote: > > > Hi Devin > > > Thank you for your reply. > > > I'm not sure if I've explained myself properly, or if I'm > > misinterpreting your reply. What I am aiming for is a form containing > > a single record. At the bottom of this form will be the pagination > > tools << Prev 1 2 3 etc. which will enable the user to navigate > > through the records individually in my form. I was hoping that the > > pagination had the ability to know the current records primary key so > > that I could render the form with a simple Data.objects.get(pk=1) this > > would then achieve the desired effect (I think). -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Pagination with bound form
Oh you want just one record per page? Thats easy. urls.py (r'^page/(?P\d+)/$', 'data.views.pagelisting'), views.py def pagelisting(request, page_number): data_list = Data.objects.filter(pk=page_number) return render_to_response('list.html', {"data_list": data_list}) template list.html {% if datalist %} {% for data in datalist %} {{ data.text }} {% endfor %} http://testsite.com/page/{%pk - 1%}>Next Page {% else %} No data is available. {% endif %} On Oct 15, 6:43 am, David <cthl...@gmail.com> wrote: > Hi Devin > > Thank you for your reply. > > I'm not sure if I've explained myself properly, or if I'm > misinterpreting your reply. What I am aiming for is a form containing > a single record. At the bottom of this form will be the pagination > tools << Prev 1 2 3 etc. which will enable the user to navigate > through the records individually in my form. I was hoping that the > pagination had the ability to know the current records primary key so > that I could render the form with a simple Data.objects.get(pk=1) this > would then achieve the desired effect (I think). -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: use django authentication for non-django pages
You could use a template in django if your only serving some static html. Otherwise if its php or something, make a template and restrict it to admin and have the view render the php and spit it out to the page context. On Oct 15, 2:12 am, bowlbywrote: > We're hosting a small site on our own server. On the server we have > some pages that are non-django (for example munin to see server > statistics). Is there a way to use django's authentication mechanism > to reserve access to these pages to users who have an account? > > Details: > we have site say,www.test.comwhich is a django app. Then we > havewww.test.com/muninwhich serves static html-pages. These should only > be accessible to django admin users. Normally we would use htpasswd > but maybe there's a nicer solution. > > Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using a non-DB backend
Hello, It looks like you want a custom database backend. On http://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#engine they say "You can use a database backend that doesn't ship with Django by setting ENGINE to a fully-qualified path (i.e. mypackage.backends.whatever). Writing a whole new database backend from scratch is left as an exercise to the reader; see the other backends for examples." So i suppose you can look to the other backends for examples. Regards, Devin Morin On Oct 15, 6:21 am, Damir Dezeljin <damir.dezel...@dezo.org> wrote: > Hi. > > I'm working on an application tat communicates with embedded devices > connected to the LAN. The devices are controlled by a central server written > in C++. Django is used for the front-end or better to say the GUI for the > server. > > Part of the data the user needs access too are stored in the database, hence > the Django DB API to access this data; however, there are certain data and > actions that requires direct communication with the C++ server. The > communication is implemented using CORBA (OmniORBpy). E.g. of a situation > where the CORBA interface between the GUI and the server is needed is the > flush of devices configuration or update of the following and this should be > real time and not implemented polling the DB. > > Currenly I'm instantiating the CORBA interface to my server in the views.py. > I'm wondering if there is a better way to do it as I just don't see how > could I put the CORBA interface in the Model part of the GUI? << I'm still > confused by MVC approaches certain frameworks like CakePHP use. I think > Django is not such a framework; however, I still think I should somehow > separate the data layer from the business logic (bottomline: Django is still > kind of a MVC framework). How can I do this? > > Of course I would also like to solve the problem I'm currently facing: > Let's suppose both the C++ server and Django web site are up and running. If > the C++ server is restarted the web page doesn't work any more until when I > restart the web server too. I instantiate the CORBA object in a global > scope; however, I thought there is no persistence for the Django code > between the web browser calls. Am I right? Why the connection to CORBA > ceases working in such a case? << with e.g. C++ or Python stand-alone > clients the connection is reestablished each time the script / program / ... > is executed. > > Thanks for any hint you may have, > Damir -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Legacy database with a table, which has no separate primary key
Wait... I just looked at your sql and it looks like you would need to use multiple-column primary keys which are unsupported by django. http://code.djangoproject.com/ticket/373 On Oct 15, 4:15 am, Alexanderwrote: > I have a database, which among others has the following tables: > > CREATE TABLE users ( > userId BIGINT PRIMARY KEY > ); > > CREATE TABLE movies ( > movieId BIGINT PRIMARY KEY, > title varchar(255) NOT NULL > ); > > CREATE TABLE ratings ( > userId BIGINT NOT NULL REFERENCES users(userId), > movieId BIGINT NOT NULL REFERENCES movies(movieId), > rating SMALLINT NOT NULL, > timestamp varchar(150) NOT NULL, > CONSTRAINT unique_userid_movieid UNIQUE(userId, movieId) > ); > > As you can see the 'rating' table has no separate primary key field. > > Here are the models created by Django with some my corrections: > > class Users(models.Model): > userid = models.BigIntegerField(primary_key=True) > > def __unicode__(self): > return u"User %d" % self.userid > > class Meta: > db_table = u'users' > > class Movies(models.Model): > movieid = models.BigIntegerField(primary_key=True) > title = models.CharField(max_length=255) > users = models.ManyToManyField(Users, through='Ratings', > related_name="rated_movies") > > def __unicode__(self): > return self.title > > class Meta: > db_table = u'movies' > > class Ratings(models.Model): > user = models.ForeignKey(Users, db_column='userid') > movie = models.ForeignKey(Movies, db_column='movieid') > rating = models.SmallIntegerField() > timestamp = models.BigIntegerField() > > def __unicode__(self): > return u"%d" % self.rating > > class Meta: > db_table = u'ratings' > unique_together = (("user", "movie"),) > > So having these models i can do this: > > In [1]: from django_orm.movielens.models import * > In [2]: u = Users.objects.get(pk=1) > In [3]: u.rated_movies.all() > Out[3]: [,..] > > or this: > > In [4]: m = Movies.objects.get(pk=1) > In [5]: m.users.all().count() > Out[5]: 2264 > > But i can't get the "ratings" objects because trying this: > > Ratings.objects.filter(user=1) > > or this: > > u.ratings_set.all() > > causes the following error > > DatabaseError: column ratings.id does not exist > LINE 1: SELECT "ratings"."id", "ratings"."userid", > "ratings"."moviei... > > Is there a way to tell Django, that 'Ratings' models does not have a > separate primary key? Or my only option is to add the column to the > 'ratings' table? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Legacy database with a table, which has no separate primary key
I did some quck googling and found this. http://stackoverflow.com/questions/605896/django-querying-read-only-view-with-no-primary-key This is the response from them that seems most helpful. "all you need is a column that is guaranteed to be unique for every row. Set that to be 'primary_key = True in your model and Django will be happy." Regards, Devin Morin On Oct 15, 4:15 am, Alexander <potapovsa...@gmail.com> wrote: > I have a database, which among others has the following tables: > > CREATE TABLE users ( > userId BIGINT PRIMARY KEY > ); > > CREATE TABLE movies ( > movieId BIGINT PRIMARY KEY, > title varchar(255) NOT NULL > ); > > CREATE TABLE ratings ( > userId BIGINT NOT NULL REFERENCES users(userId), > movieId BIGINT NOT NULL REFERENCES movies(movieId), > rating SMALLINT NOT NULL, > timestamp varchar(150) NOT NULL, > CONSTRAINT unique_userid_movieid UNIQUE(userId, movieId) > ); > > As you can see the 'rating' table has no separate primary key field. > > Here are the models created by Django with some my corrections: > > class Users(models.Model): > userid = models.BigIntegerField(primary_key=True) > > def __unicode__(self): > return u"User %d" % self.userid > > class Meta: > db_table = u'users' > > class Movies(models.Model): > movieid = models.BigIntegerField(primary_key=True) > title = models.CharField(max_length=255) > users = models.ManyToManyField(Users, through='Ratings', > related_name="rated_movies") > > def __unicode__(self): > return self.title > > class Meta: > db_table = u'movies' > > class Ratings(models.Model): > user = models.ForeignKey(Users, db_column='userid') > movie = models.ForeignKey(Movies, db_column='movieid') > rating = models.SmallIntegerField() > timestamp = models.BigIntegerField() > > def __unicode__(self): > return u"%d" % self.rating > > class Meta: > db_table = u'ratings' > unique_together = (("user", "movie"),) > > So having these models i can do this: > > In [1]: from django_orm.movielens.models import * > In [2]: u = Users.objects.get(pk=1) > In [3]: u.rated_movies.all() > Out[3]: [,..] > > or this: > > In [4]: m = Movies.objects.get(pk=1) > In [5]: m.users.all().count() > Out[5]: 2264 > > But i can't get the "ratings" objects because trying this: > > Ratings.objects.filter(user=1) > > or this: > > u.ratings_set.all() > > causes the following error > > DatabaseError: column ratings.id does not exist > LINE 1: SELECT "ratings"."id", "ratings"."userid", > "ratings"."moviei... > > Is there a way to tell Django, that 'Ratings' models does not have a > separate primary key? Or my only option is to add the column to the > 'ratings' table? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Pagination with bound form
So you have a page number thats getting passed from a url, right? and then you want to display records based on that page number? you could do something like this: urls.py (r'^page/(?P\d+)/$', 'data.views.pagelisting'), views.py def pagelisting(request, page_number): records = range(page_number + 10) data_list = Data.objects.filter(pk=records) return render_to_response('list.html', {"formset": formset}) template list.html {% if formset %} {% for data in formset %} {{ data.text }} {% endfor %} {% else %} No data is available. {% endif %} Might not be 100 percent on the code but i hope it helps. Regards, Devin Morin I think this would work because you can see them using an array in http://docs.djangoproject.com/en/dev/topics/db/queries/#the-pk-lookup-shortcut -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Save Handlers and a newbie to Django
Hello everyone, I am writing a save handler in my models.py file to run a few actions after a save. to do this I have a function called make_photos and a connection to the post_save signal. Here is my code: class Album(models.Model): title = models.CharField(max_length=200) date = models.DateField(blank=True, null=True) desc = models.TextField(blank=True, null=True) comments = models.BooleanField() published = models.BooleanField(default=True) tags = models.CharField(max_length=200, blank=True, null=True) def __unicode__(self): return u'%s' % (self.title) class Photo(models.Model): title = models.CharField(max_length=200, default='Untitled Photo') album = models.ForeignKey(Album, blank=True, null=True) desc = models.TextField(blank=True, null=True) date = models.DateField(blank=True, null=True) comments = models.BooleanField() published = models.BooleanField(default=True) tags = models.CharField(max_length=200, blank=True, null=True) thumb_photo = models.ImageField(upload_to='thumb_images', blank=True, null=True) large_photo = models.ImageField(upload_to='large_images', blank=True, null=True) original_photo = models.ImageField(upload_to='original_images', blank=True, null=True) def makeimages(self): (dirName, fileName) = os.path.split(self.original_photo.path) (fileBaseName, fileExtension)=os.path.splitext(fileName) #Save the thumbnail thumb_width = 300 thumb_height = 300 thumb = Image.open(self.original_photo.path) thumb.resize((thumb_width,thumb_height), Image.ANTIALIAS) thumb_path = "/tmp/" + str(fileBaseName) + "_thumb.jpg" thumb.save(thumb_path, "JPEG") thumb_img_file = open(thumb_path, 'r') thumb_file = File(thumb_img_file) self.thumb_photo.save(str(fileBaseName) + '_thumb.jpg', thumb_file, save=True) thumb_img_file.close() #Save the large large_width = 1024 large_height = 768 large = Image.open(self.original_photo.path) large.resize((large_width,large_height), Image.ANTIALIAS) large_path = "/tmp/" + str(fileBaseName) + "_large.jpg" large.save(thumb_path, "JPEG") large_img_file = open(thumb_path, 'r') large_file = File(thumb_img_file) self.thumb_photo.save(str(fileBaseName) + '_large.jpg', large_file, save=True) large_img_file.close() post_save.connect(makeimages) The only problem i have with this code is that it runs every save. So it creates a infinite loop of sorts and I dont know how to make it perform this action once. Is there another signal I should use? Any ideas? Regards, Devin M -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: HttpResponse post
I have no problem pulling pages using httplib if the pages do not require authentication. But now I want to pull pages only after authenticating. Access is enforced by the contributed auth package. import httplib, urllib params = urllib.urlencode({'this_is_the_login_form':1,'username': 'myuser', 'password': 'test'}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} conn = httplib.HTTPConnection("myserver") conn.request("POST", "/login/", params, headers) response = conn.getresponse() print response.status, response.reason As I said, when hitting pages that do not require auth, I am successful and get a 200 response code. But when auth is needed, I get 302 for the code and "found" for the status. Any insights? On Feb 17, 12:28 pm, Antoni Aloywrote: > 2009/2/17 Miguel :> thanks karen, that is what I meant. > > >>> importhttplib, urllib > >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) > >>> headers = {"Content-type": "application/x-www-form-urlencoded", > > ... "Accept": "text/plain"} > > >>> conn =httplib.HTTPConnection("musi-cal.mojam.com:80") > >>> conn.request("POST", "/cgi-bin/query", params, headers) > >>> response = conn.getresponse() > >>> print response.status, response.reason > 200 OK > >>> data = response.read() > >>> conn.close() > > Hope it helps! > > -- > Antoni Aloy López > Blog:http://trespams.com > Site:http://apsl.net --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Just switched to trunk - Special unicode handling is making me less than happy
I'm having to add calls that look like this to my code so that stuff doesn't blow up when passing model strings to other libraries: oldsteadylib.func( smart_str(str) ) # forcing unicode back to bytestring Ouch. Ugly. Reminds me of the bad old days of working with strings in C++. >From what I read, in Python 3, the default character encoding will be UTF-8 and this should obviate the need for writing conversions and using other ugly syntax to differentiate between string encodings. In the meantime, is there a configuration setting that I can use to disable unicode for django until I want to deal with special unicode syntax, if ever? I've also read that you can change your system wide encoding from ASCII to UTF-8 by changing the setencoding() in /usr/lib/python2.5/site.py. Would anyone recommend this approach? Again, my goal is to keep the strings in my code clean from special conversions. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
static css/js links from templates residing in nested directories
I've just started using template inheritance (nice) and I have some include files that I've placed in a common base. These are things you would see in the head of an html file like css and js files, for example: The files are statically served by Apache. All is working well, except some of my templates are in different folders in a directory structure. f1 template1.html |_f2 |template2.html |template3.html When the pages are rendered, the media directory is rooted at the subfolder instead of the root folder. Therefore the css and js files are not detected unless the templates reside at root. One solution would be to serve all templates out of the top directory. But of course I don't want to do that. Another solution would be to provide a complete URI in the src tag: http://mytestsite/js/mootools/mootools.svn.js"</a>; type="text/javascript"> But I don't want to do that either. Yet another solution is to provide a different relative path depending on which directory my page is served from. Perhaps there is a template tag that allows something like this? I see the MEDIA_URL variable in settings.py, however this doesn't seem to be relevant here, thought there is not much in the documentation about this. Any ideas? Did I miss the obvious solution? -- Devin --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---