Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to figure out the syntax to import a model from a different app now that ModelForms are in play #15

Closed
dgets opened this issue Oct 15, 2018 · 3 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@dgets
Copy link
Owner

dgets commented Oct 15, 2018

Running into the same problem that I originally had from #5 again, now that I've switched from using models & forms separately in subadd to utilizing ModelForms to avoid redundancy. This is in trying to find the proper solution to #11, which I just closed, as everything seems to be working, except for accessing the query of the Substance records.

@dgets dgets added bug Something isn't working enhancement New feature or request labels Oct 15, 2018
@dgets dgets added this to the alpha milestone Oct 15, 2018
@dgets dgets self-assigned this Oct 15, 2018
@dgets
Copy link
Owner Author

dgets commented Oct 15, 2018

See also:

sub = forms.ForeignKey('subadd.Substance', on_delete=models.CASCADE)

...which I have replaced with sub = forms.ModelChoiceField(queryset=subadd.Substance), along with at least a dozen other variations (including variations of from imports).

@georgedorn
Copy link

Try:

from subadd.models import Substance
[...]
sub = forms.ModelChoiceField(queryset=Substance.objects.all())

Later, you may want to change that queryset dynamically, for instance to filter by the currently-logged-in user. A pretty solid example of doing this is here:

https://stackoverflow.com/questions/51512606/django-forms-queryset

@dgets
Copy link
Owner Author

dgets commented Oct 15, 2018

How exceedingly odd, I could swear that I tried exactly that. I bet I tried every combination of things like it, but never matched up those 2 lines properly. m(

Thank you for your input, sir. It is much appreciated.

@dgets dgets closed this as completed in 248b901 Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants