reverse-lookup

DJANGO: How to list_display a reverse foreign key attribute?

大兔子大兔子 提交于 2019-12-22 04:20:46
问题 I'm building a web app that tracks what library books a person checks out. I have the following models: class Person(models.Model): name = models.CharField(max_length=100) def __unicode__(self): return self.name class Book(models.Model): name = models.CharField(max_length=100) person = models.ForeignKey(Person) checkout_date = models.DateTimeField('checkout date') def __unicode__(self): return self.name On the Admin's "change list" page for Person, I would like to show what books that person

Does Java have a HashMap with reverse lookup?

耗尽温柔 提交于 2019-12-17 02:12:12
问题 I have data that is organized in kind of a "key-key" format, rather than "key-value". It's like a HashMap, but I will need O(1) lookup in both directions. Is there a name for this type of data structure, and is anything like this included in Java's standard libraries? (or maybe Apache Commons?) I could write my own class that basically uses two mirrored Maps, but I'd rather not reinvent the wheel (if this already exists but I'm just not searching for the right term). 回答1: There is no such

Unable to use SUBSTITUTE(ADDRESS(MATCH))) combination as a range in a LOOKUP function in Excel

会有一股神秘感。 提交于 2019-12-13 19:24:24
问题 I have an Excel sheet containing a matrix of [Year & Week number] in rows and [name of Employees] in row1 giving values of available weekly hours. I am able to successfully use the Excel formula =LOOKUP(2,1/((A:A=2018)*(B:B=31)),D:D) at cell F2 for a reverse lookup. It gives the result 15 correctly. However, I wanted to replace range D:D in the above formula to a dynamic range by identifying the column when the employee is known. So I tried replacing by the formula SUBSTITUTE(ADDRESS(1,MATCH(

Reverse lookup for Java Enums with more than one value per key/constant?

北城以北 提交于 2019-12-11 09:13:58
问题 With an enum like this one where each key has several values ABBR1("long text 1", "another description 1", "yet another one 1"), ABBR2("long text 2", "another description 2", "yet another one 2"), //and so on... how can I reverse lookup an abbreviation (constant) by calling a method like getAbbreviation(descriptionText) ? I'm basically looking for an implementation as described here, I think, but with the difference that each ENUM key (constant) has several values coming with it, and I want

DJANGO: How to list_display a reverse foreign key attribute?

谁说我不能喝 提交于 2019-12-05 04:42:53
I'm building a web app that tracks what library books a person checks out. I have the following models: class Person(models.Model): name = models.CharField(max_length=100) def __unicode__(self): return self.name class Book(models.Model): name = models.CharField(max_length=100) person = models.ForeignKey(Person) checkout_date = models.DateTimeField('checkout date') def __unicode__(self): return self.name On the Admin's "change list" page for Person, I would like to show what books that person has. Is this something that can be done? If so, how? admin.py class BookAdmin(admin.ModelAdmin): list

Python: Reverse DNS Lookup in a shared hosting

陌路散爱 提交于 2019-12-03 21:37:27
Is there any way to do a reverse lookup using python, to check the list of websites sharing the same IP address in a shared hosting. Some web sites offer a tool for this purpose . DNSPython Technically, you can use DNSPython to do a reverse lookup. Pip install it $ pip install dnspython Then do your reverse query: >>> from dns import resolver >>> from dns import reversename >>> addr = reversename.from_address("74.125.227.114") >>> resolver.query(addr, "PTR")[0] <DNS IN PTR rdata: dfw06s16-in-f18.1e100.net.> socket.gethostbyaddr You can also use socket.gethostbyaddr >>> import socket >>> name,

Using Python's list index() method on a list of tuples or objects?

风流意气都作罢 提交于 2019-11-28 15:28:16
Python's list type has an index() method that takes one parameter and returns the index of the first item in the list matching the parameter. For instance: >>> some_list = ["apple", "pear", "banana", "grape"] >>> some_list.index("pear") 1 >>> some_list.index("grape") 3 Is there a graceful (idiomatic) way to extend this to lists of complex objects, like tuples? Ideally, I'd like to be able to do something like this: >>> tuple_list = [("pineapple", 5), ("cherry", 7), ("kumquat", 3), ("plum", 11)] >>> some_list.getIndexOfTuple(1, 7) 1 >>> some_list.getIndexOfTuple(0, "kumquat") 2 getIndexOfTuple(

Using Python's list index() method on a list of tuples or objects?

半城伤御伤魂 提交于 2019-11-27 09:12:40
问题 Python's list type has an index() method that takes one parameter and returns the index of the first item in the list matching the parameter. For instance: >>> some_list = ["apple", "pear", "banana", "grape"] >>> some_list.index("pear") 1 >>> some_list.index("grape") 3 Is there a graceful (idiomatic) way to extend this to lists of complex objects, like tuples? Ideally, I'd like to be able to do something like this: >>> tuple_list = [("pineapple", 5), ("cherry", 7), ("kumquat", 3), ("plum", 11

Does Java have a HashMap with reverse lookup?

﹥>﹥吖頭↗ 提交于 2019-11-26 11:21:12
I have data that is organized in kind of a "key-key" format, rather than "key-value". It's like a HashMap, but I will need O(1) lookup in both directions. Is there a name for this type of data structure, and is anything like this included in Java's standard libraries? (or maybe Apache Commons?) I could write my own class that basically uses two mirrored Maps, but I'd rather not reinvent the wheel (if this already exists but I'm just not searching for the right term). uckelman There is no such class in the Java API. The Apache Commons class you want is going to be one of the implementations of