Skip to content
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

How do I display meaningful previews for my models? #246

Open
preslavrachev opened this issue Feb 23, 2021 · 6 comments
Open

How do I display meaningful previews for my models? #246

preslavrachev opened this issue Feb 23, 2021 · 6 comments

Comments

@preslavrachev
Copy link

I know that the admin tries to make sense of the field names within the struct types and display the ones that make sense. However, it often falls into a situation, where it literally has no clue. Then, we end up having something like:

User#12345

image

What would be the preferred way to hint at QOR Admin which fields to use when displaying a preview?

@raven-chen
Copy link
Member

raven-chen commented Feb 24, 2021

hi @preslavrachev
Could you provide more context info? Where and when did you see this?

@preslavrachev
Copy link
Author

hi @preslavrachev
Could you provide more context info? Where and when did you see this?

@raven-chen Everywhere, where a relation is displayed. Say I have an order that has a user. If the user struct has no name attribute, I would get a list of orders, where in the column user, instead of seeing something humanly-readable (e.g. an email, or first namd + last name), I basically see something like the above. The same applies for when attaching a user to an order. I don't see humanly readable identifiers in the dropdowns, but some machine generated concatenation of the struct name and the id (all my model IDs are UUIDs BTW, I have a function that does that upon creation).

does that make sense?

@lutfuahmet
Copy link

type Sample struct {
    Name string //add this field for label
    Email string
}

func (s *Sample) BeforeSave() {
  if s.Name == "" {
      s.Name = s.Email
  }
}

@preslavrachev
Copy link
Author

type Sample struct {
    Name string //add this field for label
    Email string
}

func (s *Sample) BeforeSave() {
  if s.Name == "" {
      s.Name = s.Email
  }
}

Yeah, that's what I did too. If you mark the field as ignored by Gorm, it works, but it's a very obscure way of solving the problem. Relying on an established interface implementation (e.g. Stringer) would be much cleaner, IMO.

@willvictor
Copy link

Agreed that adding a "stringer" as an option for resources would be great!

@gstvg
Copy link

gstvg commented Jul 7, 2021

This is an undocumented feature, just add the method Stringify() string to your model, with value receiver, cause pointer receiver won't work.

It's implemented here:

https://github.com/qor/qor/blob/bfbb16ecbc40da17c123aa7cd7211b47caa31391/utils/utils.go#L164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants