jazzband / django-payments

Universal payment handling for Django.
https://django-payments.readthedocs.io
Other
1.06k stars 282 forks source link

Admin for payments #418

Open paulocoutinhox opened 2 months ago

paulocoutinhox commented 2 months ago

Hi,

There is any admin for this payments?

Thanks.

mariofix commented 2 months ago

Hi! I'm curious because most of the work is done automatically, what would you like to see in an admin?

I personally use django-baton and I can manage most payment cases editing the payment object.

paulocoutinhox commented 2 months ago

No, i don't see admin things for the models/payments.

WhyNotHugo commented 2 months ago

We don't currently ship an admin. I can't really imagine an implementation that would make sense; each project will have needs that are too specific in this sense.

FWIW, creating an admin is pretty simple. I use the following in one of my applications:

@admin.register(models.Payment, site=backoffice)
class PaymentAdmin(PaymentMixin, admin.ModelAdmin):
    view_on_site = False
    list_display = (
        "_display",
        "status",
        "variant",
        "order",
    )
    readonly_fields = (
        "invoice_type",
        "_display",
    )
    search_fields = ("order__pk",)
    raw_id_fields = (
        "order",
        "author",
        "receipt",
    )

    def get_queryset(self, request: HttpRequest) -> QuerySet[models.Payment]:
        return super().get_queryset(request).select_related("order")

    def has_add_permission(
        self,
        request: HttpRequest,
        obj: models.Payment | None = None,
    ) -> bool:
        return False

    def has_delete_permission(
        self,
        request: HttpRequest,
        obj: models.Payment | None = None,
    ) -> bool:
        return False

    def has_change_permission(
        self,
        request: HttpRequest,
        obj: models.Payment | None = None,
    ) -> bool:
        return False
paulocoutinhox commented 2 months ago

Im not mean external admin, but im searching for the admin classes that make it appear on django admin.

The PaymentAdmin class that you sad above is the answer.

WhyNotHugo commented 2 months ago

We can probably include it as an example in the docs.