-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
ChainedForeignKey should also provide an option by means of which we can target a specific field #310
Comments
Hi @SilverFoxA, We had the same problem when trying to convert a Foreign Key using to_field option, which smart selects does not support. I'm marking this as a feature request. |
Hello @manelclos, Have you found any workaround yet? I'm trying to debug but failed to see any request log on the console/network. |
@SilverFoxA after looking carefully at your example, I think that what smart selects needs to implement is following relationships in the chained field, in your case that would be something like: chained_field="product_option_id__option_id", That would be an As a workaround, I think you would be successful by adding a Foreign Key to Option in the ProductOptionValue model, this is untested: class ProductOptionValue(models.Model):
id = models.AutoField(db_index=True, primary_key=True)
price = models.DecimalField(db_index=True, max_digits=19, decimal_places=4)
price_prefix = models.CharField(max_length=1, choices=PRODUCT_OPTION_PREFIX, default="+")
product_option_id = models.ForeignKey(
'catalog.ProductOption',
db_index=True, on_delete=models.CASCADE,
)
option_id = ChainedForeignKey(
'catalog.Option',
chained_field="product_option_id",
chained_model_field="option_id",
show_all=False,
auto_choose=True,
sort=True
)
option_value_id = ChainedForeignKey(
'catalog.OptionValue',
chained_field="option_id",
chained_model_field="option_id",
show_all=False,
auto_choose=True,
sort=True
) |
@manelclos Thank you for your prompt response. I would suggest we look at an approach similar to what you have suggested
The other workaround which you have pointed is something we want to ignore as that will not work for the instance when the product is being created. There's another approach where we ignore the entire For now we are going for a quickfix with the |
Any update on this yet? currently having the same issue. Are there alternatives, any response will be appreciated. Thanks. |
Any update here? Or alternatives |
You MUST use this template when reporting issues. Please make sure you follow the checklist and fill in all of the information sections below.
All versions of django-smart-selects prior to version 1.2.8 are vulnerable to an XSS attack as detailed in issue 171. As a result, all previous versions have been removed from PyPI to prevent users from installing insecure versions. All users are urged to upgrade as soon as possible.
Checklist
Put an
x
in the bracket when you have completed each task, like this:[x]
master
branch of django-smart-selects.smart_selects
app.models.py
,forms.py
, andviews.py
with problems.Steps to reproduce
Actual behavior
Inline form don't show any fields.
Expected behavior
Ideal case is that we should be able to see the options.
I'm trying to address the following:
If you notice this
ChainedForeignKey
field, we are referring to the model but the ideal chained_field should beoption_id
from the modelProductOption
Is there an option where instead of just defining the entire model we can also refer to a particular field as the
chained_field
?The text was updated successfully, but these errors were encountered: