Re: prevent AppConfig.ready() from running twice

2018-06-25 Thread clavierplayer
Thanks so much, y'all! Very helpful! On Sunday, June 24, 2018 at 3:47:48 AM UTC-4, Mike Dewhirst wrote: > > On 23/06/2018 6:17 PM, Melvyn Sopacua wrote: > > On zaterdag 23 juni 2018 02:01:06 CEST Mike Dewhirst wrote: > > > >> Is there a python singleton pattern which might work? > > No, cause

prevent AppConfig.ready() from running twice

2018-06-21 Thread clavierplayer
Hello, I am still new to Django, so I apologize if this seems like a silly question. I've not been able to find what I need on Google, StackOverflow, or the Django Docs. I am using Django 2.0.5. I understand that the correct way to run startup code is to subclass AppConfig and override

avoiding import-time queries

2018-07-26 Thread clavierplayer
I'm looking for some best-practice (or at least workable) suggestions for avoiding import-time queries. I have some database records that are constant, and these constants are used all over the application. Is there any way to get those constants out of the database once at startup? At

Re: avoiding import-time queries

2018-07-27 Thread clavierplayer
I've been experimenting with it and it seems to be working pretty well. Thank you, Julio! On Thursday, July 26, 2018 at 2:28:18 PM UTC-4, Julio Biason wrote: > > Hi Clarvierplayer, > > Dunno if that's a best practice, but I'd add a module in the same app with > functions to retrieve the

Re: trying to learn custom validators

2018-07-17 Thread clavierplayer
Oh, this is perfect! Works exactly the way I need it. Thank you so much for your help! On Monday, July 16, 2018 at 5:12:40 PM UTC-4, Matthew Pava wrote: > > What I would do in that situation is add a custom field to the model form > that holds the item number. Then, in the save method, convert

trying to learn custom validators

2018-07-16 Thread clavierplayer
I have a legacy database that we want to replace, and Django is still new to us. There are some 40,000 items in the old db, and each item has an item_number that is not necessarily the primary key; that way, the users can maintain their own sku number system and we can maintain data integrity

Re: help with get_form_kwargs

2018-07-16 Thread clavierplayer
I would actually prefer to override clean(), but CreateView doesn't appear to have a clean() method that I can override. I did make a ModelForm to use with the CreateView, but the clean_item method I defined there never gets called--breakpoints and print statements are all skipped, so I don't

Re: help with get_form_kwargs

2018-07-16 Thread clavierplayer
Ah, thank you for the link; it put me on the right track, I think, with custom validators. As an example of why I need to customize the item fetching: I have an item that has an item_number of '515874'. That number is how the users interact with the item. However, the primary key for Item

trouble with forms/CreateView

2018-07-16 Thread clavierplayer
I seem to be having trouble understanding some of how form validation works, resulting in two problems. I am trying to write a CreateView in which a user can type in an item number, and the program will use that instead of the item's primary key to perform the lookup. The docs appear to

help with get_form_kwargs

2018-07-16 Thread clavierplayer
I have a CreateView in which I need to alter the user input. I may have found a way to do so using get_form_kwargs, but I'm puzzled by a couple of things: I know that kwargs['data'] is a QueryDict, which is immutable. So I tried the doc's QueryDict.copy() recommendation: def

tests pass individually but fail together

2018-07-05 Thread clavierplayer
Hello, I'm simplifying a previous post. I just started using Django a few months ago, and for some reason I'm still having trouble getting my mind around the way Django thinks about some things. I have a test class that contains two specific tests that always pass when run just by themselves,

Re: tests pass individually but fail together

2018-07-05 Thread clavierplayer
It's a script that's supposed to run in the background for an inventory management program. The basic idea is that it periodically collects Order objects that are associated with a particular Status (1-M foreign key, though more like 1-1 in practice). Orders have one or many Orderlines. Then

Re: tests pass individually but fail together

2018-07-06 Thread clavierplayer
Hi Melvyn, I've been working on getting permission to post the code, but everybody who can do that is on vacation at present, unfortunately. I'm hoping somebody will be back to work on Monday. I did try the test --parallel 1, but that didn't help. The problem tests all cover a particular

formaction vs get_absolute_url

2018-07-12 Thread clavierplayer
I'm looking for a way to redirect to a different page depending upon which submit button the user clicks. I included a formaction tag in the template, but django still demands that get_absolute_url be defined. Using Django 2.0 Basically, I'm trying to write a small app that launches a test

Re: formaction vs get_absolute_url

2018-07-12 Thread clavierplayer
Relevant urls: app_name = "utils" urlpatterns = [ path('', index, name="index"), path('', index, name="index"), path('migrate/', migrate, name="migrate"), # -- Box Opt Evaluation urls -- path('box-optimization/instructions', instruct,

Re: formaction vs get_absolute_url

2018-07-13 Thread clavierplayer
Thank you for the clear explanation! It works beautifully now. On Friday, July 13, 2018 at 9:17:37 AM UTC-4, Daniel Roseman wrote: > > On Thursday, 12 July 2018 21:04:25 UTC+1, clavie...@gmail.com wrote: >> >> I'm looking for a way to redirect to a different page depending upon >> which submit

TestCase vs TransactionTestCase

2018-07-03 Thread clavierplayer
Hello, I'm looking for some insight for some odd behavior with some unit tests, which I think stems from some misunderstanding of how these classes actually work. 1. For TestCase, the Django docs say that it does matter what order in which the tests are run. But elsewhere in the same doc, it

ModelForm: overriding is_valid()

2018-07-13 Thread clavierplayer
I have an Item model. It has both a primary key and an item number; the users refer to item numbers when finding things, and the actual primary key is not exposed. I'm trying to write a CreateView that will allow the user to input the item number. I see that CreateView defaults to using the

UpdateView: input always rejected

2018-11-20 Thread clavierplayer
I need to render some form fields by hand in order to meet style requirements. I am using UpdateView instead of a ModelForm since I just need a couple of foreign key fields that are already defined on the model, and I am using html elements to prevent invalid data from being entered. I'm