-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Trying to do list:reference returns error #472
Comments
@gi0baro having a list:reference is pretty essential for what i'm currently making and without this i really can't move foward and can't continue using emmett... |
@SvenKeimpema I'm sorry this blocks you, but there's really not so much Emmett can do for you at the moment on many relations and forms. The proper way at the moment would be to manually handle the multiple forms on your own, and the relevant add/remove logic in the template as well. Note that you should be able to make all the forms you want in a single page, eg: @app.route()
async def my_forms():
form = await ModelA.form()
form_related = await ModelB.form()
return locals() in the upper code, you can manually set the Without further information about your use-case I'm afraid there's no other option here. |
@gi0baro what i currenly mean is that if i have a form for say ModelA.form() and i want it to have many references to ModelB like:
this will return an error if i insert [1, 2](which are the id's of modelB) into ModelA, For example:
(it will throw the error i typed above) |
@SvenKeimpema yes, that's correct. As per documentation 1:N relations are provided by class ModelA(Model):
has_many({'modelb_ids': 'ModelB'})
class ModelB(Model):
refers_to({'model_a': 'ModelA'})
random_field = Field.text() so then you can: a = ModelA.create()
ModelB.create(random_field="1", model_a=a.id)
ModelB.create(random_field="2", model_a=a.id) |
@gi0baro not exactly, yes i want a N->1 relation however if i use has_many in a form
it will not show the has_many field in the form, which in the form i want to be able to select relations to said form.
i want to be able to select those fields in the form when i am in ModelA. |
@SvenKeimpema I get your point, the thing IMHO is that you need to decide which side of the 1:N relationship is 1 and which one is N. If the relationship is 1:N for ModelA:ModelB, and you want to create
If you end-up with a general-purpose solution for this, maybe you can create an |
i was trying to do a list:reference to a table however i noticed that the has_many isn't an actual field(which is needed for it to go into a form). whenever i tried adding a list of references to refers_to it also threw an error:
full traceback:
is there any way to get a list of references without using has_many or can you make it so has_many works in forms?
The text was updated successfully, but these errors were encountered: