AN country code in maxmind database, what country does it refer to? - country-codes

Selecting distinct(country) from my maxmind database i found country with code "AN", that is not in list here:
http://dev.maxmind.com/geoip/codes/iso3166
and on wiki:
http://en.wikipedia.org/wiki/ISO_3166-1
For which country it can refer to?

According to http://www.iso.org/iso/home/standards/country_codes/iso-3166-1_decoding_table.htm
This is Netherlands Antilles

Related

List of missing records for reverse OneOnOneField in django

I have two models with the same primary key:
class OperationalDevice(models.Model):
ip = models.GenericIPAddressField(primary_key=True)
mac = models.CharField()
class AllowedDevice(models.Model):
ip = models.OneToOneField(OperationalDevice, primary_key=True, on_delete=models.DO_NOTHING, db_constraint=False, db_column='ip')
type = models.CharField()
owner = models.CharField()
I would like to display the list of all AllowedDevices that are down - kind of like:
SELECT AllowedDevice.ip from AllowedDevice
LEFT OUTER JOIN OperationalDevice ON
AllowedDevice.ip = OperationalDevice.ip
WHERE OperationalDevice.ip is NULL
I tried using AllowedDevice.objects.filter(ip__...), but it creates inner join. I also tried objects.exclude and objects.annotate, and they also create a query with inner join
Maybe I should't be using OneToOneField?
Making the relationship go the other way is not a solution, because I need to find both kinds of exceptions - devices that are in one table but not the other.
This is related to my previous question:
I have two tables with the same primary key.
ip mac
11.11.11.11 48-C0-09-1F-9B-54
33.33.33.33 4E-10-A3-BC-B8-9D
44.44.44.44 CD-00-60-08-56-2A
55.55.55.55 23-CE-D3-B1-39-A6
ip type owner
22.22.22.22 laptop John Doe
33.33.33.33 server XYZ Department
44.44.44.44 VM Mary Smith
66.66.66.66 printer ZWV Department
The first table is automatically refreshed every minute. I can't
change the database structure or the script that populates it.
Both tables have ip as PRIMARY KEY.
In a view, I would like to display a table like this:
ip mac type owner Alert
11.11.11.11 48-C0-09-1F-9B-54 Unauthorized
55.55.55.55 23-CE-D3-B1-39-A6 Unauthorized
22.22.22.22 laptop John Doe Down
66.66.66.66 printer ZWV Department Down
33.33.33.33 4E-10-A3-BC-B8-9D server XYZ Department OK
44.44.44.44 CD-00-60-08-56-2A VM Mary Smith OK
How can I model this? Should I make one of the two primary keys a
foreign key into the other one?
Once the code is in operation, there will be lots of data, so I want
to make sure it's fast enough.
What is the fastest way to retrieve the data?
To use left outer join you should use .values('one_to_one_field__sub_filed') or .annotate(sub_field=F('one_to_one_field__sub_filed')):
from django.db.models import F
AllowedDevice.objects.all().annotate(mac=F('ip__mac'))
But I think that you really need a "FULL JOIN" that can only be simulated using QS.union(). See the last part (Using OneToOneField for better SQL) of answer to your original question for details.

Django query: get the last entries of all distinct values by list

I am trying to make a Django query for getting a list of the last entries for each distinct values from a MySQL database. I will show an example below as this explanation can be very complicated. Getting the distinct values by themselves obviously in Django is no problem using .values(). I was thinking to create couple of Django queries but that looks to be cumbersome. Is there an easy way of doing this.
For the example below. Suppose I want the rows with distinct Names with their last entry(latest date).
Name email date
_________________________________________________
Dane dane#yahoo.com 2017-06-20
Kim kim#gmail.com 2017-06-10
Hong hong#gmail.com 2016-06-25
Dane dddd#gmail.com 2017-06-04
Susan Susan#gmail.com 2017-05-21
Dane kkkk#gmail.com 2017-02-01
Susan sss#gmail.com 2017-05-20
All the distinct values are Dane, kim, Hong, Susan. I also want the rows with the latest dates associated with these distinct name. The list with entries I would like is the rows below. Notice Names are all distinct, and they are associated with the latest date.
Name email date
_________________________________________________
Dane dane#yahoo.com 2017-06-20
Kim kim#gmail.com 2017-06-10
Hong hong#gmail.com 2016-06-25
Susan Susan#gmail.com 2017-05-21
with postgresql you should able to do:
EmailModel.objects.all().order_by('date').distinct('Name')
for more methods/functions like this, you can visit the docs here
This only applies to POSTGRES
You can use the ORDER_BY command to set your query set as ordered by date, then chain with the DISTINCT command to get distinct rows and specify which field. The DISTINCT command will take the first entry for each name. Refer The Docs For More
Edit
For MYSQL, you will have to use raw SQL queries, refer here
Only Postgres supports providing field names in distinct. Also, any field provided in values and order_by is in distinct, thus providing ambiguous results sometimes.
However for MySQL:
Model.objects.values('names').distinct().latest('date')

InfoPath attachment in a repeating table

First of all, Thank You. Here is my Boondoggle...
Currently, users are required to do regular training which is printed
and stored in user's manila folder.
My objective:
Create a SharePoint List page with InfoPath forms for each training item.
Included in this form:
Training Title/Description/Due date
User Name - Repeating table pulled from a data connection to a SharePoint list with "User Names".
(60 users max, this list also has title, name, phone number)
A PDF attachment for their certificate of completion.
EXAMPLE:
Blow your nose today.
Due Date 08-23-2013
Name Attachment
Joe Smith XZX.PDF
Bill Smith YYY.PDF
Jack Smith ZXZ.PDF
I am able to create the repeating table list of names from the 'user names' List.
But, I cannot figure out a way to attach a file to each name individually.
I add a file and it populates the entire list.
Joe Smith AAA.PDF
Bill Smith AAA.PDF
Jack Smith AAA.PDF
Any ideas would be greatly appreciated, Thank you in advance!

how to lookup a city name by facebook's City Id?

Or, I'm fine downloading all the cities in a country, and searching in memory.
It's actually quite simple but not (obviously) documented... Just query http://graph.facebook.com/106078429431815 with 106078429431815 being the city id (London in this example).

Django GeoIP get country by city name

I'm using GeoIP for geo location with django and it works fine - locates city, country etc. But what i want is to locate the country name if is searched the city name. Example:
Search: Madrid
Found country: Spain
Search: Paris
Found country: France
Is this possible with GeoIP and if it is, how?
Thanks!
It's not possible. GeoIP can only map IP to country/city, that's all.
You should try experimental Google Places API - you can use it to check in which country eg. Madrid is.