Code Monkey home page Code Monkey logo

django-addanother's Introduction

image

django-addanother provides you with add-another buttons for forms outside the Django administration interface. It also provides an optional integration with django-select2.

See documentation for details.

django-addanother has been extracted from django-autocomplete-light v2, after noticing that other apps copied the same code, to ease community maintenance.

django-addanother's People

Contributors

blueyed avatar cleitondelima avatar ikcam avatar jonashaag avatar jpic avatar luzfcb avatar mangelozzi avatar n1k1tas95 avatar olivierdalang avatar sterliakov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-addanother's Issues

Custom get parameters

Hi,

Currently, one can't add custom get parameters to the urls, because ?popup=1 gets appended to the end. So you end up with test.com/myurl/?custom=abc?popup=1 which isn't valid.

I have a fix but it doesn't apply to master (since I work on the edit_links branch) : olivierdalang@b89ea33

I'll open a PR when the edit_links branch gets merged.

Update fields of the same form

How do I update fields of the same form using the same model?

Example:

...
'client': AddAnotherEditSelectedWidgetWrapper(
      forms.Select,
      reverse_lazy('client-create'),
      reverse_lazy('client-update', args=['__fk__'])
),
 'sender': AddAnotherEditSelectedWidgetWrapper(
      forms.Select,
      reverse_lazy('client-create'),
      reverse_lazy('client-update', args=['__fk__'])
)

Docs: view.is_popup

I don't get the "if" in this template. What does <nav>...</nav> mean here?

If the view is a popup the navigation should be hidden....

Or is there a negation missing in the template snippet?

{{{
You may want to hide header, footer and navigation elements for the popups. When the create view is opened in a popup, the view.is_popup template variable is set:

{% if view.is_popup %}
  <nav>...</nav>
{% endif %}

}}}
http://django-addanother.readthedocs.org/en/latest/usage.html?highlight=popup#make-your-view-popup-compatible

Django 4.1 support

Hi there!
Since I've updated Django from version 4.0.7 to 4.1, django-addanother does not work properly.
The popup, when I'm click on the plus button, does not show up, but instead it just opens another page (in the same browser tab).
Also, in the opened page, when i add new object, it throws an error:

popup_response.js:13` Uncaught TypeError: Cannot read properties of null (reading 'dismissAddRelatedObjectPopup')
at popup_response.js:13:16

I'll be glad to supply other info or code if requested.

Concurrent implementation

Hi

I failed to find your repo before making my own implementation. This issue is about removing my duplicate repo. The two implementations differ though, so I'd like to know your thoughts about the possibilities we have to unite the repos.

Here are the differences:

What do you think ? Would you prefer to upgrade to the newer implementation, add it and support both, or just keep it in two separate apps ?

Best

Why no "edit" button as well ?

Hi !

This app is great, nice and simple.
Did you consider allowing to add the "edit" button as well ?

It could be either specific wrapper classes, or an argument to choose between add link only, edit link only, or both links.

Thanks !

Widget state shared between form instances

Two bugs here:

  1. We should be using deepcopy to make copies of the inner widget to avoid state sharing of inner widgets if someone passes a widget instance rather than a widget class. django/django@09da1e7

  2. We should make sure that when a widget is being copied using deepcopy, the inner widget is deepcopied too.

Using addanother not for add but for choose ?

At first thank you for very good and useful add-ons.

I have mostly a question than an issue. Sorry to ask it here, the issues are probably not for this purpose, but I didn't find any other place to ask it.
My problem is that I want to use django-addanother add-on not for add the new item, but to choose from existing one.

In two words...

I have a model with ForeignKey field. In the form this field is done using Select Dropdown menu.
I'd like instead to have a button that will open a popup window where user choose the Object, click Submit, then popup is closed and the chosen Object is inserted into initial Form.

So my questions are :

  1. Do you think I could realize such functionality with django-addanother ?

  2. Is this functionality already included in django-addanother ? I could not find any explicit example in the doc.

  3. I allow myself to ask this question as the desired functionality is not very hard to obtain.
    In fact, if in the very basic example we inherit class PersonCreate not form CreateView but from ListView we could easily get the list of related objects :

class PersonCreate(CreatePopupMixin, ListView):

The only question is that I should return from this PersonCreate popup to get it into thi initial form.

Once again, sorry for this not very relevant question.

Error on migrate in test_project

Hi! i just cloned the repo and when i try to run the migrate command, the console throws the follow error:
django.db.utils.OperationalError: no such table: auth_group

Any idea?

Thanks!

django-addanother disables django-smart-selects

Hi,

My project relies heavily on django-smart-selects.
After i integrated django-addanother into my project, django-smart-selects (out of admin) stopped working. I think It's something related to javascript in the view created by smart-selects which is being overwritten or deleted by addanother.
I use overridden valid_form() method like this in my views:

from django_addanother.views import PopupMixin
class LuogoCreate(PopupMixin, CreateView):
    success_url = reverse_lazy("ipms:nuovo_luogo")

[...]

 def valid_form(self, form, addanother, savecontinue, delete):
        self.object = form.save()
        if addanother:
            return redirect("nrms:nuovo_luogo")
        elif savecontinue:
            return redirect("nrms:modifica_luogo", self.object.id)
        elif delete:
            return redirect("nrms:elimina_luogo", self.object.id)
        elif self.is_popup():
            return self.respond_script(self.object)
        else:
            return redirect("nrms:luoghi")

Any hints?

No popup when different variable name for form

Hi folks,

I noticed that the popup mechanism does not work when the view sends, for the form, a variable that has a different name than 'form'.

This works, and a new window pops-up when clicking on the add button :
image

At contrario, this does not work, whereas I made the changes in the template of course :
image
The form and the button are well displayed, but it opens the new form in the same window instead of poping-up.

I think it's a bug since it's just the variable the template uses, thus this sould not have an impact.

I'm using Django 4.1.7 and python 3.11.2.
Thanks a lot for the job done.

Edit-button doesn't get the fk using DAL

Hey there,

The widget works great for adding new values, no problem at all. But, the Edit button seems to fail. I'm wrapping the DAL widget and when I select a value, the fk value is never populated, and the Edit button remains disabled. Is there some trick with DAL?

Edit: To clarify, when you create a new object via addanother and return to the page the id for the new item is populated correctly, but when you pick a new one from the DAL widget, that id value never gets updated.

Cheers

AddAnotherWidgets not filled

Thanks for your great work.

I'm not sure if this is a bug or a mistake on my side (more likely), but when I load an existing instance in a form the AddAnotherWidgets are not filled with the current value. The "normal" fields are filled however.

I based my code on the example app, but that only has a submit option and does not let you load an existing instance.

Any idea what could be going wrong?

bug? or im doing something wrong? help appreciated

First of all thanks for the amazing tool!

I'm trying to use the edit/new wrapper for a select 2 widget, the multiple select to be precise .

What i'm doing is

#urls

path("models/creator/add", views.CreatorAddView.as_view(), name="creator_add"),
path("models/creator/edit/<pk>", views.CreatorEditView.as_view(), name=creator_edit"),

# form

widgets = {
    "creator" : Select2MultipleAddAnotherEditSelected(
        reverse_lazy("main:creator_add"),
        reverse_lazy("main:creator_edit", args=["__fk__"]),
    )
}

The create works fine, but the edit does some weird behavior ...

image

The data are stored in the database, so in a refresh of the page they show, but the selected value isn't changing, its just appended on the input field and its not editable or select-able.

Also, since the field is multi-select, if there are 2 or more values selected, the edit button view gets all their id as input. I get that's probably intended, but any way to disable it if none or 2+ are selected? I'm using a UpdateView.

Thanks for any help!

select2 add-another implementation

Hi,

Thanks for the app, its coming together nicely.

I am trying to integrate with select2 using the Select2AddAnother widget and its works to a certain degree.

Only issue i have is that when i add another instance and the pop-up window closes the option is selected, but not set as initial using select2 in my form.

Any ideas on this one?

Thanks guys!

Change blocktrans in link title

django-addanother use in link title the string "Edit related" and "Add another", but django uses "Change selected {{ model }}" and "Add another {{ model }}" here.

Even though it has in the context of the model, I think it would be valid to exchange this title for him to change based on the language in settings.

Could this be done? Anything I can submit a PR.

'ascii' codec can't encode characters in position... on version 1.0.1

django-addanother v. 1.0.1
I get an error if I try to put a text with accented characters like ç, ã ....


Traceback:
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  34.             return bound_func(*args, **kwargs)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  30.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/luzfcb/projetos/solar_gitlab_master/djdocuments/views/documentos.py" in dispatch
  407.         return super(TipoDocumentoCriar, self).dispatch(request, *args, **kwargs)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  89.         return handler(request, *args, **kwargs)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/views/generic/edit.py" in post
  249.         return super(BaseCreateView, self).post(request, *args, **kwargs)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django/views/generic/edit.py" in post
  215.             return self.form_valid(form)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django_addanother/views.py" in form_valid
  25.             return self.respond_script(self.object)
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django_addanother/views.py" in respond_script
  32.             escapejs(self.label_from_instance(created_obj)),
File "/home/luzfcb/virtualenvs/solar_master/local/lib/python2.7/site-packages/django_addanother/views.py" in get_script_response_html
  40.             label=created_obj_label

Exception Type: UnicodeEncodeError at /docs/t/criar_tipo_documento/
Exception Value: 'ascii' code

Formset compatibility

Jonas, thank you for creating this and putting this out there for others to use. I was able to install it and get the included demo project running with no problem. The demo is very useful to answer questions.

I am trying to get django-addanother to run correctly with a Django formset. It works fine for the first form in the formset, but in subsequent forms in the formset, upon closing, the popup window inserts the new record into the first form in the formset only. I'm not sure if there is an existing way to create the desired behavior. Is it possible or does django-addanother not accommodate formsets?

Thanks, Paul

Filter queryset with django-addanother

Hi Jonas,

is it possible to filter the given queryset of a widget based on the current user? So that the Select displays only the entries for objects that belong to the currently authenticated user?

Kind regards
Christopher

ModelSelect2AddAnother

Hi, thank you for developing django-addanother; I have been using it with the default AddAnotherWidgetWrapper widget for a while now (in Django 1.11) and it works very well. However, I am now attempting to use it in a project that requires an autocomplete widget (currently using dal.autocomplete.ModelSelect2, but would really like a popup form to create new choices).

Following your documentation (http://django-addanother.readthedocs.io/en/latest/select2.html and http://django-addanother.readthedocs.io/en/latest/reference/select2_widgets.html#select2ref), I had no trouble to reproduce the example given with Select2AddAnother, but no luck so far in my attempts to use ModelSelect2AddAnother instead.

Could you please add an example using ModelSelect2AddAnother to http://django-addanother.readthedocs.io/en/latest/select2.html ?

Many thanks!

'AddAnotherWidgetWrapper' object has no attribute 'choices'

Hi I am getting the above error, I am running Django 4.1.1 and setup the widget as follows:

 form.fields['venue'].widget = AddAnotherWidgetWrapper(
        forms.Select,
        reverse_lazy('create-venue'),
  )

Are all the Django 4x related fixes releases in pypi? I am using 2.2.2 version (the last tag I can see here is 2.1.0)
Thank you

Screenshots

  • screenshot of vanilla add another form
  • screenshot of select2 add another form

This would be nice to have in the documentation.

xvfb broken

@jpic can you have a look at the xvfb parts of the tests, they seem broken I have no idea how it works

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.