oscarmlage / django-cruds-adminlte

django-cruds is simple drop-in django app that creates CRUD for faster prototyping
BSD 3-Clause "New" or "Revised" License
424 stars 81 forks source link

ManyToMany fields #122

Closed A4TIF closed 4 years ago

A4TIF commented 4 years ago

Looks like ManyToMany fields do not work. Perhaps we can add a linked string representation of each object within columns.

123

oscarmlage commented 4 years ago

The PR was already merged, Thanks for the contribution @kptac

benmaier commented 4 years ago

hey @kptac I'm currently having the problems that ManyToMany-field values are neither shown in the list-view nor in the-display. It seems you have solved this problem with this PR but to me it's unclear how to use this. Would you mind a short explanation?

A4TIF commented 4 years ago

@benmaier - make sure to have a string representation set by implementing Model.str() method.

Also, are you on the latest version?

Hope that helps.

benmaier commented 4 years ago

Yes to both!

The __str__() method of one of the models is called if it's in a ForeignKey-field but not for a ManyToManyField.

The version I'm on is 0.0.17+git.a154def. I've clone this repo today.

benmaier commented 4 years ago

my setup is basically the one I described in #133 ... maybe the select-widget is overriding things in the display-view? That'd be rather weird though. I'd be super thankful if you could take a short look at it!

A4TIF commented 4 years ago

The latest release is: 0.0.17+git.081101d

for your geoname model, try this:

class Geoname(models.Model):
    name = models.CharField(max_length=255)
    population = models.PositiveIntegerField(blank=True,null=True)

    def __str__(self):
        return '%s' % self.name
benmaier commented 4 years ago

My Geoname-model already has this property

The latest release is: 0.0.17+git.081101d

Yes, I know, but this release is from July 10 and does not include your changes (see e.g. https://github.com/oscarmlage/django-cruds-adminlte/tree/0.0.17%2Bgit.081101d/cruds_adminlte/templates/cruds/columns where your file is missing). I'm on the latest master commit which is 0.0.17+git.a154def and includes your changes.

A4TIF commented 4 years ago

Ahh ok, my bad, didn't see the commits on the latest release. So in your CRUDView, are you including the m2m field in list_fields? Can I see how you're inheriting CRUDView?

benmaier commented 4 years ago

Ah! list_fields wasn't mentioned anywhere in the documentation, so I didn't know about it. That did the trick, thank you so much!